Macro to open another program - shortcut target has a command line switch

wadergirl

New Member
Joined
Jun 3, 2016
Messages
49
So, in my spreadsheet, I have an existing macro that uses:

Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")

So I'm pretty sure that it is the base of what I need to use for this other program, but the other program I need to use a shortcut which has a command line switch in the target filepath that I'm not sure how to include:

"C:\Users\Me\Documents\Program.exe" -switch

It doesn't work as:
Shell ("C:\Users\Me\Documents\Program.exe" -switch)
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You can look HERE for a decent explanation. You would do something like this:
Code:
[COLOR=#333333]Shell ("""C:\Users\Me\Documents\Program.exe"" -switch")[/COLOR]
 
Upvote 0
Solution
You can look HERE for a decent explanation. You would do something like this:
Code:
[COLOR=#333333]Shell ("""C:\Users\Me\Documents\Program.exe"" -switch")[/COLOR]

Thank you, that works! Unfortunately, I now get an "Unhandled exception has occurred in your application" error when the program opens, "object reference not set to an instance of an object". I can get past it by just clicking "continue" and the program is fine, so I don't know if it's a problem with opening the shortcut from Excel vs. my desktop, but I can live with it.
 
Upvote 0
You're welcome.

Try removing the parentheses and see if that clears it up. Since you are not setting a variable equal to the return value of the Shell command (which is fine, by the way), Excel doesn't like the parentheses.
 
Last edited:
Upvote 0
Nevermind! Fixed it! Used:

Call Shell ("""C:\Users\Me\Documents\Program.exe"" -switch")

instead of just

Shell ("""C:\Users\Me\Documents\Program.exe"" -switch")
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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