phill cook
phill cook

Reputation: 35

VBA: Help running cmd line from excel vba

I use a program that extracts data from pdf files and you can use cmd line to control the program, i would like to intergrate this with my excel sheet, the code below works when pasted in to cmd just fine but when i try from VBA it isnt working.

this is what ive managed to find online, help will be very appreciated.

sCommandToRun = "C:\Program Files (x86)\A-PDF Data Extractor\PDECMD.exe" -R"Accord new" -F"C:\Users\phill\Desktop\Test.pdf" -O"C:\Users\phill\Desktop\results.xlsx" -Txlsx -PA

Call Shell("cmd.exe /S /C" & sCommandToRun, vbHide)

aslo if there is a way to wait until the cmd line has finished before i excute another line of code would also be a big help.

Thanks

Upvotes: 0

Views: 198

Answers (2)

phill cook
phill cook

Reputation: 35

changing '"Shell "cmd.exe /C " & sCommand, vbHide" to "Shell sCommand, vbHide" did the trick some some reason – phill cook just now Edit

Upvotes: 0

CDP1802
CDP1802

Reputation: 16392

Add quotes around the paths with spaces in them.

Option Explicit
Sub test()

    Dim sCommand As String
    sCommand = """C:\Program Files (x86)\A-PDF Data Extractor\PDECMD.exe""" & _
           " -R""Accord new""" & _
           " -F""C:\Users\phill\Desktop\Test.pdf""" & _
           " -O""C:\Users\phill\Desktop\results.xlsx"" -Txlsx -PA"    
    'Debug.Print sCommand
    Shell "cmd.exe /S /C " & sCommand, vbHide
    
End Sub

Upvotes: 1

Related Questions