使用VBA Outlook在点击标签上打开URL

时间:2019-03-01 13:55:44

标签: vba outlook

当我单击表格中的标签时,如何打开网页? 例如:

我有URL“ https://stackoverflow.com/questions/ask”,并在Form Outlook VBA上贴有标签。 当我单击标签时,我想打开默认浏览器,并希望看到该网站页面-https://stackoverflow.com/questions/ask

如何创建它?

1 个答案:

答案 0 :(得分:0)

您可以使用Windows API ShellExecute 进行此操作。

要使用它,请在表单/模块代码上面这样声明它

Private Declare Function ShellExecute _
                            Lib "shell32.dll" _
                            Alias "ShellExecuteA" ( _
                            ByVal hwnd As Long, _
                            ByVal lpOperation As String, _
                            ByVal lpFile As String, _
                            ByVal lpParameters As String, _
                            ByVal lpDirectory As String, _
                            ByVal nShowCmd As Long) _
                            As Long

然后您可以执行以下操作:

Private Sub Label1_Click()

    Dim r As Long
    Dim strUrl

    ' Define the URL
    strUrl = "https://stackoverflow.com/questions/ask"

    '  Open the URL
    r = ShellExecute(0, "open", strUrl, 0, 0, 1)

End Sub

它将在默认浏览器中打开URL