2017-02-09 269 views
0

我想用我的默認瀏覽器打開URL。使用默認瀏覽器打開瀏覽器/ URL

我試圖使用「Call Shell("C:\Program Files (x86)\Mozilla Firefox\firefox.exe -url" & strUrl, 1)」,但Firefox不會打開URL。相反,Firefox從我的默認頁面開始。

當我使用「Call Shell(strURL,1)」即時通訊獲取「文件未找到」錯誤。

Private Sub openurl_Click() 
    Dim urlopen As String 
    Dim User As String 
    Dim pass As String 

     urlopen = URL.Value 
     User = Username.Value 
     'pass = Passwort.Value 
     pass = InputBox("Passwort eingeben") 
     strUrl = "https://" & User & ":" & pass & "@" & urlopen 

     'MsgBox strURL <- TEST OUTPUT 

     'Call Shell("C:\Program Files (x86)\Mozilla Firefox\firefox.exe -t" & strUrl, 1) 
     'Call Shell(strURL, 1) 

    End Sub 

回答

1

嘗試的Application.FollowHyperlink代替Call Shell

Application.FollowHyperlink strURL 
+0

運行時錯誤16388.廣東話跟隨超級鏈接 – rel0aded0ne

+0

這串那樣你用strURL?它應該以「https://」開始,而不是「cmd」等。因此,Application.FollowHyperlink https://www.google.com「'會打開默認瀏覽器。作爲URL您可以使用其他任何東西,包括文件名 –

1

下面是我在訪問應用程序處理這個問題的方式,用100%的成功爲止。 它直接調用Windows API SHELL32.DLL

1.創建一個模塊,並補充一點:

'------------------------------------------------------------------------ 
' Open an external application - Advanced way 
'------------------------------------------------------------------------ 
Public Declare Function ShellExecute _ 
    Lib "shell32.dll" Alias "ShellExecuteA" (_ 
    ByVal hWnd As Long, _ 
    ByVal Operation As String, _ 
    ByVal FileName As String, _ 
    Optional ByVal Parameters As String, _ 
    Optional ByVal Directory As String, _ 
    Optional ByVal WindowStyle As Long = vbMinimizedFocus _ 
) As Long 


'------------------------------------------------------------------------ 
' Open Webpage in default browser 
'------------------------------------------------------------------------ 
Public Sub OpenUrl(strURL) 
    Dim lSuccess As Long 
    lSuccess = ShellExecute(0, "Open", strURL) 
End Sub 

2.從你的代碼,打開你的URL是這樣的:

OpenUrl "http://anything.com" 

您可以進一步擴大ShellExecute函數來打開任何東西el se,而不僅是網址

1

我得到了一個解決方案。也許這裏有人對它有意思。

Private Sub openurl_Click() 
    Dim urlopen As String 
    Dim User As String 
    Dim pass As String 

     urlopen = URL.Value 
     User = Username.Value 
     'pass = Passwort.Value 
     pass = InputBox("Passwort eingeben") 
     strURL = "cmd /c start https://" & User & ":" & pass & "@" & urlopen 

     'MsgBox strURL <- Test Output 

     Call Shell(strURL, 1) 

End Sub 

我加入cmd /c startstrURL字符串

strURL = "cmd /c start https://" & User & ":" & pass & "@" & urlopen 

這似乎是一個「髒」的解決方案,但它的工作原理:d

+0

適合我! https://www.computerhope.com/starthlp.htm – chiliNUT