当我点击表格中的标签时,如何打开网页?例如:
我在表格Outlook VBA上有“https://stackoverflow.com/questions/ask”和标签。当我点击标签时,我想打开默认浏览器,我想看到这个网站页面 - https://stackoverflow.com/questions/ask
如何创建它?
您可以使用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