2017-02-09 229 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