All templates
ScriptingAdvanced
Convert Excel to PDF Using VBScript
Robomotion•Updated 6 months ago

Overview
Runs an inline VBScript that drives Excel COM to export a workbook as PDF. Shows how to bridge Robomotion with Windows scripting.
Convert Excel to PDF Using VBScript
Although UI automation nodes can replicate any manual task, scripting can be a more time-effective solution for some scenarios. For example, Robomotion users can efficiently convert Excel files to PDF using VBScript code instead of interacting with multiple Excel UI components.
What Convert Excel to PDF Using VBScript can do
- Build paths (
Core.Programming.Function) — setsmsg.fixtures_dir,msg.sample_xlsx(bundledsample.xlsx) andmsg.output_dirunder$Home$/templates/.../fixtures. - Input Dialog (
Core.Dialog.InputBox) titledConvert Excel to PDF, defaultmsg.sample_xlsx→msg.excel_path; then a second dialog with defaultmsg.output_dir→msg.destination_folder. - Validate (
Core.Programming.Function,outputs: 2) — requires an.xls/.xlsxpath and a destination; computesmsg.pdf_path = destination_folder\\ConvertedPDFfile.pdfandmsg.script_path = destination_folder\\_convert.vbs. Invalid input routes toCore.Flow.Stop. - Ensure destination (
Core.FileSystem.Create,optType: directory,continueOnError: true) againstmsg.destination_folder. - Build script (
Core.Programming.Function) — substitutes${EXCEL_PATH}and${PDF_PATH}in the VBScript template (quoting backslashes and double quotes) →msg.vbs_body. - Write VBS (
Core.FileSystem.WriteFile,optMode: truncate,optBase64: false) tomsg.script_path, then buildmsg.vbs_args = ['//Nologo', msg.script_path]. - Run script (
Core.Process.StartProcess,inFilePath: cscript,optBackground: false) →msg.vbs_output, thenCore.FileSystem.Deleteonmsg.script_path(continueOnError: true). - Show done (
Core.Dialog.MessageBox,info) titledThe flow ran successfully.withmsg.dialog_text = 'The generated PDF file is stored at: ' + msg.pdf_path, thenCore.Flow.Stop.
Behind the scenes
ExportAsFixedFormat 0, ...is Excel COM'sxlTypePDF. The trailing0, 1, 0, , , 0sets quality (standard), include doc properties, ignore print areas — the positional semantics matter, so preserve the argument list verbatim.- Path values are interpolated by escaping
\\and"in the Function node before being written into the VBScript literal, which avoids quote-injection when the source or destination contains awkward characters. - The script exports the active sheet only, not every sheet in the workbook. Multi-sheet export requires a different, longer script that loops through
Worksheets. _convert.vbsis written next to the PDF and deleted aftercscriptexits so no script artifact is left behind.