0

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

1
  • Why would you need cmd.exe to run another executable from VBA? Commented Jul 19, 2021 at 14:02

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

hi CDP1802 appreciate the help, when i check the debug print the line of code is correct and when i paste it in to cmd it works but it isnt working when i run the vba code
@phill Try without /S
ive tried with out the /s but still seems to be the same, i am getting a secuity warning when i try to run the code "Malicious Macros detected"
changing '"Shell "cmd.exe /C " & sCommand, vbHide" to "Shell sCommand, vbHide" did the trick some some reason
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.