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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,856
Messages
6,127,362
Members
449,381
Latest member
Aircuart

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