2013-05-08 23:44:33 +0000 2013-05-08 23:44:33 +0000
49
49
Advertisement

我可以使用excel公式提取单元格中超链接的链接位置吗?

Advertisement

我有一个电子表格,其中有大量的单元格包含超链接,其显示文字与超链接位置

即:

单元格位置不同。A1

display text = “Site Info”

hyperlink location = http://www.mylocation.com

有没有一个excel公式允许我访问超链接位置的文本字符串?

理想情况下,它应该是这样的。

FORMULA(A1) = http://www.mylocation.com

Advertisement

答案 (3)

55
55
55
2013-05-09 00:20:34 +0000

你可以使用一个宏。

  • 打开一个新的工作簿。
  • 进入VBA(按Alt+F11键)
  • 插入一个新的模块(Insert > Module)
  • 复制并粘贴下面的Excel用户定义函数
  • 退出VBA(按Alt+Q键)
  • 对这个自定义的Excel函数使用以下语法: =GetURL(cell,[default_value])
22
22
22
2015-05-01 09:34:26 +0000

我只需要从单个单元格的值中提取地址,所以我发现这个小函数很方便:

与 “蛮力 "宏相比,你也可以创建一个用户定义的函数,它将提取并返回任何指向它的超链接的URL:

Function GetURL(rng As Range) As String
     On Error Resume Next
     GetURL = rng.Hyperlinks(1).Address 
End Function

在这种情况下,你可以把它放在你想要的地方。例如,如果你想把A1中的超链接的URL列在单元格C25中,那么在单元格C25中输入以下公式。

=GetURL(A1) http://excel.tips.net/T003281_Extracting_URLs_from_Hyperlinks.html

2
Advertisement
2
2
2017-01-30 09:54:57 +0000
function EXTRACT_URL(input) {

  var range = SpreadsheetApp.getActiveSheet().getRange(input);
  var re = /^.+?\(\"(.+?)\",.+?$/;
  if (input.indexOf(':') != -1) {
    var formulas = range.getFormulas();
    for (var i in formulas) {
      for (var j in formulas[i]) {
        formulas[i][j] = formulas[i][j].replace(re, "$1");
      }
    }
    return formulas;
  } else {
    return range.getFormula().replace(re, "$1");
  }

}
Advertisement