Running CMD from VBA

Dmack21

New Member
Joined
Jan 15, 2022
Messages
14
Good day,

Hoping to get some advice with the below.

When I paste the path below into CMD it operates.

"C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe" /i "Z:\TEST\FILENAME TEXT\DD-C-0001.dwg" /s "Z:\TEST\FILENAME TEXT/PLOT.scr"

Battling to run this through VBA. The below seems to be doing half the command correctly.

VBA.Shell "C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe /i ""Z:\TEST\FILENAME TEXT\DD-C-0001.dwg""", vbNormalFocus

When attempting the full command below. It is not operating.

VBA.Shell "C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe /i ""Z:\TEST\FILENAME TEXT\DD-C-0001.dwg /s """"Z:\TEST\FILENAME TEXT/PLOT.scr""""""", vbNormalFocus

I understand this would traditionally be run through a batch file which I am attempting to avoid so I can add variables down the line.

Any advice would be highly appreciated.

Thank You
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Untested but I think this should work...
VBA Code:
Shell "C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"" /i ""Z:\TEST\FILENAME TEXT\DD-C-0001.dwg"" /s ""Z:\TEST\FILENAME TEXT/PLOT.scr", vbNormalFocus
 
Upvote 0
Seems like the quotes are not correct. I would try this:

VBA Code:
VBA.Shell """C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"" /i ""Z:\TEST\FILENAME TEXT\DD-C-0001.dwg"" /s ""Z:\TEST\FILENAME TEXT/PLOT.scr"""
 
Upvote 0
Rich (BB code):
Shell "C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"" /i ""Z:\TEST\FILENAME TEXT\DD-C-0001.dwg"" /s ""Z:\TEST\FILENAME TEXT/PLOT.scr", vbNormalFocus
Rick, I think the quotes to match the ones I highlighted are missing at the beginning and end of the string. Please compare to the one I posted and let's see if we can figure out the correct version.
 
Upvote 0
Seems like the quotes are not correct. I would try this:

VBA Code:
VBA.Shell """C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"" /i ""Z:\TEST\FILENAME TEXT\DD-C-0001.dwg"" /s ""Z:\TEST\FILENAME TEXT/PLOT.scr"""
The above did the job! Thank you so much for the input. Saved me hours no doubt!
 
Upvote 0
Hi All,

I've introduced a variable and loop to the code and the shell command cannot locate the "FullPath". Any ideas of why this may be? Updated Code below. Any advice would be appreciated.

Thank You.



Sub acadupdate()

Dim fileName As Variant
Dim myfilePath As Variant
Dim FullPath As Variant


If IsEmpty(Range("B8").Value) = True Then
myfilePath = ThisWorkbook.Path & "\"
ElseIf IsEmpty(Range("B8").Value) = False Then
myfilePath = Range("B8").Value & "\"
End If

fileName = Dir(myfilePath & "\*.dwg")

While fileName <> ""

FullPath = myfilePath & fileName
MsgBox FullPath

VBA.Shell """C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"" /i "" FullPath "" /s ""Z:\TEST\FILENAME TEXT/PLOT.scr""", vbNormalFocus

fileName = Dir
Wend

End Sub
 
Upvote 0
FullPath is a VBA variable... in order to get its value into the text string, you have to concatenate it in.
 
Upvote 0
Solution
FullPath is a VBA variable... in order to get its value into the text string, you have to concatenate it in.
Hi Rick,

A bit unsure how to do this. I attempted adding the & as below. Still doesn't seem to be doing the trick.

VBA.Shell """C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe"" /i "" & FullPath & "" /s ""Z:\TEST\FILENAME TEXT/PLOT.scr""", vbNormalFocus

Thank You
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,825
Members
449,096
Latest member
Erald

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