简体   繁体   English

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

[英]Open URL on click label using VBA Outlook

How to open webpage, when i click to label in Form? 单击表单中的标签时,如何打开网页? For example: 例如:

I have url " https://stackoverflow.com/questions/ask " and label on Form Outlook VBA. 我的网址为“ https://stackoverflow.com/questions/ask ”,并在Form Outlook VBA上贴上标签。 When I click on label, i want to open default browser and I want to see this website page - https://stackoverflow.com/questions/ask 当我单击标签时,我想打开默认浏览器,并希望看到此网站页面-https://stackoverflow.com/questions/ask

How to create it? 如何创建呢?

You can use windows API ShellExecute for doing this. 您可以使用Windows API ShellExecute来执行此操作。

To use it, declare it like this atop your form/module code 要使用它,请在表单/模块代码上面这样声明它

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

Then you can do this : 然后,您可以执行以下操作:

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

And it will open the URL in the default browser 它将在默认浏览器中打开URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM