how can i open a pdf file with vbscript in chrome and search with a string in the url?

After replies I tried the following.

Tried using strUrl = escape(strUrl) but this resulted the strUrl to be fully encoded even the / and \ slashes.

Then I started checking different Urls as suggested changing my / to \ slashes as well as encoding spaces. This was my result.

When I use the url withoud encodeing spaces like

"\\myserver\HelpDocumentation\Configuration - Company Configuration.pdf#Search=Register_"

in chrome it does not encode at all and at every space in the url it opens a new tab. – Not working.

When I use

"\\myserver\HelpDocumentation\Configuration%20-%20Company%20Configuration.pdf#Search=Register_"

in chrome it changes to : file://myserver/HelpDocumentation/Configuration%2520-%2520Company%2520Configuration.pdf%23Search=Register_
Then not working because of double encoding. So it adds a “file:” and also encodes the url again, spaces and # is encoded.

When I use

file:\\myserver\HelpDocumentation\Configuration%20-%20Company%20Configuration.pdf#Search=Register_

in chrome it stays the same and in result it is working. So the “file:” appended at the start and encoding just the spaces in the url makes the difference.

I ended up with the following code. Note the strUrl is a input variable I just hardcoded for example. I also now check if its a pdf then add “file:” as the url can be a file or a report url. This code works.

Dim strChrome
Dim WShellChrome
Dim strUrl

Set WShellChrome = CreateObject("WScript.Shell")
strChrome = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
strUrl = "\\myserver\HelpDocumentation\Configuration - Company Configuration.pdf#Search=Register_"

strUrl = Replace(strUrl, " ", "%20")

if(InStr(strUrl,".pdf")) Then
   strUrl = "file:" + strUrl
End If

WShellChrome.Run strChrome & " " & ""+strUrl+"" , 1, false

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top