useR
useR

Reputation: 3082

dynamic url to browse chrome vba

According to [this link][1], @ray have use the following code to do browsing

shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url www.google.com")

While i would like to use dynamic url

Dim url as string
url = "www.google.com/translate"

Dim wholeContent as String
wholeContent =  ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe - url"" & url
Shell(wholeContent)

next time maybe maps instead of translate.

Upvotes: 0

Views: 566

Answers (1)

ignotus
ignotus

Reputation: 658

Here is a Subroutine to open a url in Chrome (either 32 or 64 bit version) or using the default browser if Chrome can not be found. I hope this helps.

Sub OpenInChromeOrDefaultBrowser(ByVal url As String)

    Dim wholeContent As String
    chrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

    If Dir(chrome, vbNormal) <> "" Then
        '' 32 bit Chrome
        wholeContent = """" & chrome & """ -url " & url
    Else
        '' 64 bit Chrome
        chrome = "C:\Program Files\Google\Chrome\Application\chrome.exe"
        wholeContent = """" & chrome & """ -url " & url
    End If

    If Dir(chrome, vbNormal) <> "" Then
        '' Chrome is found, execute
        Shell wholeContent
    Else
        '' Chrome was not found, open url using the default program
        Dim Sh As Object
        Set Sh = CreateObject("WScript.Shell")
        Sh.Run url
    End If
End Sub

Upvotes: 2

Related Questions