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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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