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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,493
Office Version
  1. 365
Platform
  1. Windows
Hi, you could try something like.

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

Macro81

New Member
Joined
Jan 29, 2021
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
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,
 

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,493
Office Version
  1. 365
Platform
  1. Windows
Any ideas?

Hi, the topic is not something that I'm readily familiar with to be honest, but for anyone to stand a chance of helping you're probably going to have to post the code you are having trouble with.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,514
Messages
5,636,782
Members
416,940
Latest member
JohanT

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
Top