vba 关注动态超链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17842091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 22:24:21  来源:igfitidea点击:

Follow dynamic hyperlink

excelvbahyperlinkexcel-2010

提问by meverhart913

I have a worksheet with four columns. Column A has an ID number, B has description, C has location and D has a link to an image of the item.

我有一个包含四列的工作表。A 列有一个 ID 号,B 有描述,C 有位置,D 有指向物品图像的链接。

I have a macro that asks the user for an ID# and searches column A. A message box displays the location of the tooling. I would like the hyperlink in Column D to open in a new window upon selecting the "Okay" button on the message box.

我有一个宏,它要求用户输入 ID# 并搜索 A 列。一个消息框显示工具的位置。我希望在选择消息框上的“确定”按钮后,在新窗口中打开 D 列中的超链接。

Here's what I have so far.

这是我到目前为止所拥有的。

Dim FindString As String
Dim Rng As Range
FindString = InputBox("Enter Tooling ID#")
If Trim(FindString) <> "" Then
    With Sheets("Sheet1").Range("A:A") 
        Set Rng = .Find(What:=FindString, _
                    After:=.Cells(.Cells.Count), _
                    LookIn:=xlValues, _
                    LookAt:=xlWhole, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlNext, _
                    MatchCase:=False)
        If Not Rng Is Nothing Then
            Application.Goto Rng, True 'value found
            MsgBox "Tooling " & Rng & " is located at " & Rng.Offset(, 2).Value & "."

        Else
            MsgBox "Tooling not found" 'value not found
        End If
    End With
End If

回答by Andy G

To follow a Hyperlink and open it in a new window (True):

要跟踪超链接并在新窗口中打开它 (True):

    Range("A8").Hyperlinks(1).Follow (True)

It should open in the appropriate application.

它应该在适当的应用程序中打开。

Hyperlink.Follow

超链接。关注

If if is not configured to open in the appropriate application, then you might read the link-address from the cell and investigate using Shellto start, for example, Paint:

如果未配置为在适当的应用程序中打开,则您可以从单元格中读取链接地址并调查使用Shell以启动,例如,Paint:

Shell "MSPaint ""F:\Documents and Settings\student\My Documents\My Pictures\blog1.png"""