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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi, you could try something like.

VBA Code:
Shell(ProgAddress & " """ & FileAddress & """")
 
Upvote 0
Solution
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
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.
 
Upvote 0

Forum statistics

Threads
1,215,754
Messages
6,126,679
Members
449,328
Latest member
easperhe29

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