使用默认浏览器打开浏览器/ URL

时间:2017-02-09 13:27:37

标签: vba ms-access

我想用默认浏览器打开一个网址。

我尝试使用“Call Shell("C:\Program Files (x86)\Mozilla Firefox\firefox.exe -url" & strUrl, 1)”但firefox不会打开该网址。相反,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

3 个答案:

答案 0 :(得分:3)

我有一个解决方案。也许这对某人来说很有意思。

    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 start添加到strURL字符串

strURL = "cmd /c start https://" & User & ":" & pass & "@" & urlopen
它似乎是一个肮脏的&#34;解决方案,但它的工作原理:D

答案 1 :(得分:1)

尝试使用Application.FollowHyperlink代替Call Shell

Application.FollowHyperlink strURL

答案 2 :(得分:1)

以下是我在Access应用中处理此问题的方式,目前为止取得了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。在您的代码中,打开您的网址:

OpenUrl "http://anything.com"

您可以进一步展开ShellExecute功能以打开其他任何内容,而不仅仅是网址