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?
    – aschipfl
    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
4
  • 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 cook
    Commented Jul 19, 2021 at 10:48
  • @phill Try without /S
    – CDP1802
    Commented Jul 19, 2021 at 10:52
  • 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"
    – phill cook
    Commented Jul 19, 2021 at 11:22
  • changing '"Shell "cmd.exe /C " & sCommand, vbHide" to "Shell sCommand, vbHide" did the trick some some reason
    – phill cook
    Commented Jul 19, 2021 at 11:33
0

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.