Excel to PDF using vbscript

crwill

New Member
Joined
Apr 17, 2012
Messages
2
I have been able to convert an Excel worksheet to PDF, however it only does the active worksheet. How can I get it to put all the worksheets in an Excel file to one PDF? Here is what I have:

function excel_app(filename)
strExt = objFSO.GetExtensionName(filename)
wscript.echo strExt
strfilename = objFSO.GetBaseName(filename)
strfilename = strfilename & "." & "pdf"
wscript.echo strfilename
' Create an Excel instance
Dim myExcelWorker
Set myExcelWorker = CreateObject("Excel.Application")
' Disable Excel UI elements
myExcelWorker.DisplayAlerts = False
myExcelWorker.AskToUpdateLinks = False
myExcelWorker.AlertBeforeOverwriting = False
myExcelWorker.DefaultFilePath = "C:\BatchFiles\NewFiles"
'stFilePath = myExcelworker.DefaultFilePath & "\" & strfilename
'Wscript.Echo strFilePath
'Need some way to get the filename from the directory
'I'm thinking along the lines of FSO, but not sure on how
set objDoc = myExcelWorker.Workbooks.Open(filename,,True)

objDoc.ActiveSheet.ExportAsFixedFormat 0, strfilename, 0, 1, 1,,,0

myExcelWorker.Quit
set myExcelWorker = Nothing

end function
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,215,398
Messages
6,124,694
Members
449,179
Latest member
kfhw720

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top