why doesnt followhyperlink open website + shell syntax solution explanation

excellol

New Member
Joined
May 5, 2020
Messages
21
Office Version
  1. 2019
Platform
  1. Windows
1) this works:
Code:
thisworkbook.FollowHyperlink "https://www.google.com"
(remove the space after h)

but not this:
Code:
ThisWorkbook.FollowHyperlink "https://www.bi.go.id/en/statistik/indikator/IndONIA.aspx"

instead i got either one of these errors:
1624890226515.png

1624890935409.png


why is this so? both are normal websites so theoretically it should work?


2) i found this solution on stackoverflow which is able to open my website
Shell "explorer ""Indicator"""

could u explain the syntax to me? i tried googling for the shell syntax explanation but they werent helpful for my context
what does 'explorer' refer to? im sure that it isn't explorer.exe, as the code opened the website in my default browser which is firefox
why are there double quotes ("") for the website?
lastly, i used the shell code above for each of the 4 websites that i want to open. however, the websites did not open in the order of the shell code. is there a way to make them open in order?

for eg
Shell "explorer ""website1"""
Shell "explorer ""website2"""
Shell "explorer ""website3"""

firefox opened websites 1 and 3 followed by website 2
 
Last edited by a moderator:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
im sure that it isn't explorer.exe
But it is. The double quotes are there because it is a literal string within the argument being passed to the shell command.
 
Upvote 0
But it is. The double quotes are there because it is a literal string within the argument being passed to the shell command.
sorry i mean why are there 2 double quotes before and after the website? strings usually need only one double quote

explorer.exe opens the file explorer in my pc. how does this link to firefox?
 
Upvote 0
As I said, it's because that literal string is a quoted string within an already quoted string argument:

Rich (BB code):
Shell "explorer ""https://www.bi.go.id/en/statistik/indikator/IndONIA.aspx"""

The red quotes are surrounding the one argument being passed to the Shell command. The blue quotes are for the string argument that is actually passed to the Explorer program. If the blue quotes weren't doubled, the first one would actually close the first red quote.
 
Upvote 0
explorer.exe opens the file explorer in my pc. how does this link to firefox?
Using shell extensions, which tell explorer the correct program to use for a given file type. I could for example, enter:

Code:
explorer "c:\testing\book1.xls"

into the Windows Run box and it would load Excel with that workbook opened, because it knows what the default program for opening xls files is.
 
Upvote 0
is it possible to run the shell code with the variable replacing the website? the following code opens my file explorer instead of the website in my default browser

VBA Code:
dim msia as string

'store website link in variable
msia="https://www.bnm.gov.my/interest-rates-volumes?p_p_id=bnm_market_rate_display_portlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&_bnm_market_rate_display_portlet_product=rri&_bnm_market_rate_display_portlet_monthStart=5&_bnm_market_rate_display_portlet_yearStart=2021&_bnm_market_rate_display_portlet_monthEnd=5&_bnm_market_rate_display_portlet_yearEnd=2021"

shell "explorer msia"
 
Upvote 0
You need:

Code:
shell "explorer """ & msia & """"
 
Upvote 0
could u explain the intuition behind using 3 quotation marks and "&"?
 
Upvote 0
Using a simpler link, let's say we want to pass this to the Shell command:

Code:
explorer "http://www.mrexcel.com"

but we want to use a variable for the address, so we try:

Code:
dim add as string
add = "http://www.mrexcel.com"
Shell "explorer add"

That doesn't work because it literally passes explorer add to the Shell command, not the value of the add variable. That happens because add is within the quotes. So we try:

Code:
dim add as string
add = "http://www.mrexcel.com"
Shell "explorer " & add

(That will actually work, because you don't need the quotes round a simple link like that, but you do with your link so let's pretend it doesn't!)

what that passes to the Shell command is Explorer http://www.mrexcel.com which is missing the quotes we want. Now, as I mentioned before, to get a literal quote mark inside a quoted string, we need to double it. So:

Rich (BB code):
Shell "explorer " & add

needs a quote added within the first quoted string - hence:

Rich (BB code):
Shell "explorer """ & add

and then we need to append another quote at the end, so finally we have:

Rich (BB code):
Shell "explorer """ & add & """"

Does that make sense?
 
Upvote 0
Rich (BB code):
Shell "explorer """ & add & """"

this part
Rich (BB code):
" & add & "
is the string to be passed in the main string (ie "explorer ") ?

if yes, am i right we would then get "explorer & add &" ?

why do we need a second & after add ?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,086
Members
449,206
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top