我需要从VBA打开浏览器,其中必须从单元格中读取URL。如果我在调用中使用URL作为字符串,它工作正常但是当我尝试从单元格调用URL时出现错误,因为它在前面添加了HTTP
这个有效
Set browser = CreateObject("InternetExplorer.Application")
browser.Visible = True
browser.Navigate ("https://ITMIXI01AP.ICSITA.NET/InforIntSTS/connect/authorize?client_id=infor~62hEkBLpdrXINBI5Byh4NVAu9JuZmpO7NyMANis65xU&response_type=code&redirect_uri=http://localhost:3000/redirect.html")
这个没有:
wClientId = ws.Range("C19")
wClientSecret = ws.Range("C20")
wTokenUrl = ws.Range("C21")
wTokenResource = ws.Range("C22")
wRedirecURI = ws.Range("C23")
InforOSURL = Chr(34) + Trim(wTokenUrl) + Trim(wTokenResource) + "?client_id=" + Trim(wClientId) + "&response_type=code&redirect_uri=" +
Trim(wRedirecURI) + Chr(34)
InforOSURL = Trim(InforOSURL)
Set browser = CreateObject("InternetExplorer.Application")
browser.Visible = True
browser.Navigate InforOSURL
答案 0 :(得分:0)
另一种方法是使用ShellExecute()
函数。
除了能够打开任何文档外,它还可以使用默认浏览器打开并导航到网页。此外,通过提供verb
,您可以执行打印,编辑等操作。
以下示例具有静态Open
操作。
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
Public Sub MyShellExecute(ByVal Path As String)
ShellExecute 0, "Open", Path, "", "", vbNormalNoFocus
End Sub
要打电话:
MyShellExecute "www.google.com"