【问题标题】:VBA doing a Vlookup and then a vbyesno boxVBA 做一个 Vlookup,然后是一个 vbyesno 框
【发布时间】:2018-03-17 03:48:41
【问题描述】:

我已经编写了一个 VBA 来执行 Vlookup。它正在查找索赔编号,每个 caim 在范围的第 3 列中都有一个超链接,该链接指向索赔的详细信息、图片等。Vlookup 在第 3 列中返回相关的超链接,但是我想要一个 vbyesno 框给出用户可以选择指向 Vlookup 返回的超链接并查看索赔详情。 我已经设法让它正常工作,将人们引导到一个网址(我在我的 VBA 中使用了谷歌作为例子)是否可以稍微改变我的 VBA 所以它会根据结果而不是谷歌来改变超链接查找。

这是我写的VBA

Sub check()

On Error GoTo MyerrorHandler:
Dim claim_number As String
Dim here    As String
claim_number = InputBox("please enter claim number")
If Len(claim_number) > 0 Then
    Set myRange = Range("claims")
    Set objShell = CreateObject("Wscript.Shell")
    here = Application.WorksheetFunction.VLookup(claim_number, myRange, 3, False)
    intMessage = MsgBox("The claim has been partly investigated by Ali.  Would"
                        "you like to view the details of the claim.", _
                        vbYesNo, "Great news Lee")

    If intMessage = vbYes Then
        objShell.Run ("www.google.com")
    Else
        Wscript.Quit
    End If

Else
    MsgBox "You didn't enter a claim number"
End If
Exit Sub

MyerrorHandler:
If Err.Number = 1004 Then
    MsgBox "Claim has not been invsetigated"
End If

End Sub

【问题讨论】:

  • 在不知道您的源数据的情况下,我可以告诉您,您可以使用cell.Hyperlinks(1).Address 从单元格中获取超链接地址,因此objShell.Run (cell.Hyperlinks(1).Address) 应该可以解决问题。只需将cell 替换为工作表中超链接所在的位置即可。
  • 超链接所在的单元格会发生变化。 Vlookup 将返回包含相关超链接的单元格。我怎样才能让它只使用 Vlookup 结果单元格来获取超链接
  • objShell.Run(here) ?
  • 是的。我需要它转到(此处)并指向该单元格中的超链接
  • 假设 myrange 从第 1 行开始,试试这个:objShell.Run (Cells(Application.WorksheetFunction.Match(claim_number, myrange, 0), 3).Hyperlinks(1).Address)

标签: vba excel hyperlink vlookup


【解决方案1】:

感谢各位的帮助。我已经设法解决了这个问题。 我刚刚使用了 ThisWorkbook.FollowHyperlink(这里)

如下图

Sub check()


On Error GoTo MyerrorHandler
Dim claim_number As String
Dim here As String
claim_number = InputBox("Please enter the claim number")
If Len(claim_number) > 0 Then
Set myrange = Range("claims")
Set objShell = CreateObject("Wscript.Shell")
here = Application.WorksheetFunction.VLookup(claim_number, myrange, 3, 
False)
intMessage = MsgBox("This claim has been investigated by Ali.  Would you 
like to view the details?", _
vbYesNo, "GREAT NEWS LEE")

If intMessage = vbYes Then
ThisWorkbook.FollowHyperlink (here)
Else
Wscript.Quit
End If

Else
MsgBox "You didn't enter a claim number"
End If
Exit Sub

MyerrorHandler:
If Err.Number = 1004 Then
MsgBox "This claim has not been investigated"
End If

结束子

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2021-08-29
    • 1970-01-01
    • 2018-08-24
    • 2015-07-26
    • 1970-01-01
    相关资源
    最近更新 更多