我在一列中有多个网页超链接&我想通过单击超链接在activeX Web浏览器控件中打开它们,因为如果我为每个单元格创建命令按钮或有其他可能的话,将需要更多的时间。检查例如。屏幕镜头附加
1号筛

2号筛

发布于 2022-03-14 20:01:23
您可以通过在超链接中添加前缀(如"MyLink:“)来创建自己的超链接。双击这些单元格将地址加载到浏览器控件。
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
' Define Your Own Weblink identifier
Dim MYLINKPREFIX As String
MYLINKPREFIX = "MyLink:"
' Check if the value of the doubleclicked cell is one of your "weblinks"
Dim isMyLink As Boolean
isMyLink = (Left(Target.Value, Len(MYLINKPREFIX)) = MYLINKPREFIX)
' If its one of your links, cut out the address, paste it to the browser control.
' At the end cancel the double click event of the cell, to avoid going into cell-edit mode.
If (isMyLink) Then
Dim TargetAddress As String
TargetAddress = Right(Target.Value, Len(Target.Value) - Len(MYLINKPREFIX))
WebBrowser1.Navigate TargetAddress
Cancel = True ' Cancel the Double Click to avoid edit mode
End If
End Sub检查单元格值是否以前缀开头。在工作表中的单元格双击事件中执行此操作。如果单元格值以"Mylink:“前缀开头,则可以在保留地址名的同时去掉前缀文本。
取此地址名,并使用浏览器控件打开它。
取消Doubleclick事件,如果它是您的客户网站之一,以避免单元格编辑模式,因为你只想看到网页。

我不会取消像"MyLink:“这样的长前缀,而是使用">”这样的短标记。前缀只是为了防止excel本身从值中生成超链接。
https://stackoverflow.com/questions/71450279
复制相似问题