VBA Shell Command Help

Macro81

New Member
Joined
Jan 29, 2021
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Hi

I've having trouble with the VBA shell command. I can use the basic command to launch a file directly from VBA and obtain the task ID.

E.g., ProgID=Shell("C:\addressofprogram.exe ""C:\addressoffiletobeopened.doc"""), vbNormalFocus

I'm sure this is simple. However, I can't work out how to input the program and file address into the shell command if I already have them as variables in my code.

E.g., This doesn't work: ProgID =Shell(ProgAddress & FileAddress), vbNormalFocus

Please can someone help.

Many thanks in advance.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi, you could try something like.

VBA Code:
Shell(ProgAddress & " """ & FileAddress & """")

Hi,

That worked... Brilliant thanks. The problem I'm having now is that when using AppActivate to move back to the file window it's not selected (in focus)... Although the file window does appear. I don't understand this as my original shell command includes maximized and focus statements. Any ideas?

Thanks,
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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