简体   繁体   中英

I want to open a file with a specific application using VBScript

I am trying to download some bank statements which only come in.pdf format and convert them to an excel file. I use NitroPDF.exe to convert the.pdf file to an excel file and then have created a VBA script to clean it up and append it into my main Excel file. I have to do the conversion manually up to the point where Excel VBA takes over. I would like to automate it, not sure how. I have tried to use cmd line:

"C:\Program Files\Nitro\Pro\12\NitroPDF.exe" "C:\Users\Adam\OneDrive\Desktop\TEMP\WebBroker - Balances.pdf

And that works fine in that it opens NitroPDF with the file I need in it. however when I try to run it in a.vbs file (named: RunningPdf.vbs) like this:

    Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "C:\Program Files\Nitro\Pro\12\NitroPDF.exe" "C:\Users\Adam\OneDrive\Desktop\TEMP\WebBroker - Balances.pdf", 1, true

I get an error:

Script:  C:\Users\Adam\OneDrive\Desktop\TEMP\RunningPdf.vbs  
Line: 2
Char: 59  
Error: Expected end of statement  
Code: 800A0401  
Source: Microsoft VBScript compilation error

What am I doing wrong in my translation from cmd to vbs? Should I even be using vbs for this? how could I meld this code to my Excel VBA code? I was planning to use sedkeys in the vbs code once NitroPDF opened, to automate the conversion from pdf to Excel, is this the best way? Sorry for the lengthy post, any help would be greatly appreciated Thank you

Always worth quoting file paths, but then you need to escape those quotes in the value being passed to Shell

WshShell.Run """C:\Program Files\Nitro\Pro\12\NitroPDF.exe"" ""C:\Users\Adam\OneDrive\Desktop\TEMP\WebBroker - Balances.pdf""", 1, true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM