单击CommandButton以显示带URL链接的UserForm

时间:2013-07-10 12:09:32

标签: vba excel-vba excel

我正在尝试编写CommandButton1来显示UserForm1。在Userform1中,我想要一个超链接,它使用工作表中单元格的值。我想在点击链接时卸载UserForm1。

我会放下我认为的所知。但我遗漏了大部分代码。具体做法是:

如何实际显示链接?

如何在点击链接时解码UserForm1?

Private Sub CommandButton_Click()
    UserForm1.Show
End Sub

Private Sub UserForm1_Click()
    Dim URL As Hyperlink
        URL = "http://www.example.com/" & Cells.Range("Q5") & "/index"
    ...
End Sub

1 个答案:

答案 0 :(得分:2)

我会在你的UserForm中添加一个标签。

Private Sub Label1_Click()
    Dim URL As String
    Dim cellvalue As Variant

    cellvalue = ActiveWorkbook.Sheets(1).Range("Q5").Value
    URL = "http://www.example.com/" & cellvalue & "/index"

    On Error GoTo urlnotopen
    ActiveWorkbook.FollowHyperlink Address:=URL, NewWindow:=True
    Unload UserForm
    Exit Sub
urlnotopen:
    MsgBox "Cannot open " & URL
End Sub

此致