0

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.

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

3 Comments

Hi @ignotus, Thanks for your reply. I don't know how you use ".
You have to put the path to chrome between quotes because it contains space character(s). You put escape a quote with another one, so in a string, you have to type "" to contain one quote. See more here: stackoverflow.com/questions/4835691/…
@ignotus Nice once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.