Home > front end >  Struggling to get VBA Shell to execute CMD
Struggling to get VBA Shell to execute CMD

Time:12-08

Hi Guys im trying to excute a cmd line from VBA but it keeps giveing me errors like "c:\program" is not reconised. ive been stuck here for hours adding Chr(34) and other things but still no luck.

here is my code

Path = """C:\Users\Phill\Desktop\Mortgage Illustration 211206142739.pdf"""
scommand = """C:\Program Files (x86)\A-PDF Data Extractor\PRCMD.exe""" & _
       Path

Shell "cmd.exe /k " & scommand, vbNormalFocus

CodePudding user response:

Maybe something like this:

Dim exe, pth

exe = "C:\Program Files (x86)\A-PDF Data Extractor\PRCMD.exe"
pth = "C:\Users\Phill\Desktop\Mortgage Illustration 211206142739.pdf"

Shell "cmd.exe /k """"" & exe & """ """ & pth & """""", vbNormalFocus

EDIT: fixed - the whole command (exe plus path) also needs to be quoted...

  • Related