在我的 Excelsheet 中,我使用了一个带有来自 sql-server 的数据源的表。
其中一列包含电话号码,另一列包含邮件地址。
现在我想创建一个像 tel:09999999
这样的超链接或 mailto:test@test.com
打开默认的 Windows 应用程序以开始通话或写电子邮件。
单元格的格式是通用的。
不幸的是,超链接是纯文本而不是超链接。我看到像 =hyperlink("tel:09999999";"09999999")
这样的公式.当我单击单元格时,按 [F2]
- 键并按回车键,然后 excel 将单元格值更改为“正确”超链接。
我尝试的第二个想法是为所有这些单元格编写一个宏。但性能不好,我有大约 20000 行 5 列,所以 excel 运行大约 1 分钟只用于创建超链接。
代码如下所示:
lastrow = ActiveSheet.Cells(Cells.Rows.Count, 1).End(xlUp).Row
For i2 = 4 To lastrow
'Phone1
Worksheets("Report").Cells(i2, 11).Select
If Len(Selection.Value) > 0 Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="tel:" + CStr(Selection), TextToDisplay:=CStr(Selection)
End If
'Phone2
Worksheets("Report").Cells(i2, 12).Select
If Len(Selection.Value) > 0 Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="tel:" + CStr(Selection), TextToDisplay:=CStr(Selection)
End If
'Phone3
Worksheets("Report").Cells(i2, 13).Select
If Len(Selection.Value) > 0 Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="tel:" + CStr(Selection), TextToDisplay:=CStr(Selection)
End If
'Mail1
Worksheets("Report").Cells(i2, 14).Select
If Len(Selection.Value) > 0 Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="mailto:" + CStr(Selection), TextToDisplay:=CStr(Selection)
End If
'Mail2
Worksheets("Report").Cells(i2, 15).Select
If Len(Selection.Value) > 0 Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="mailto:" + CStr(Selection), TextToDisplay:=CStr(Selection)
End If
Next i2
最佳答案
我想指出的是,每个国家/地区的 Office 版本之间存在细微差别。换句话说,他们使用不同的设置,例如日期设置、分隔符以及最后......不同的公式。
例如,超链接的“标准”(原始、通用)公式是:
=HYPERLINK("tel:09999999","09999999")
我们可以在波兰语版本的 Excel 应用程序中使用的本地公式是:
=HIPERŁĄCZE("tel:09999999";"09999999")
如你看到的:
您可以在此处找到有关它的更多详细信息:
Range.Formula
Range.FormulaLocal
Application.International Property (Excel) .
因此,如果您想通过 VBA 代码插入公式,该代码使用 [
;
],您必须使用 FormulaLocal
属性(property)。如果您想使用 Formula
插入公式属性,你必须关心正确分隔符的使用!因此,插入公式的保存方式应该是一个表单:
'English (universal way)
oSheet.Range("A1").Formula = "=HYPERLINK(""tel:00009"",""000009"")"
'German
oSheet.Range("A1").FormulaLocal = "=HYPERLINK(""tel:00009""" & Application.International(xlListSeparator) & """000009"")"
至于您的代码...您已被警告使用
Select
方法。祝你好运!
关于sql - Excel中的超链接不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50576953/