I used to be on Excel 2003 (lovely that), and I used to print out invoices etc to a pdf file with this macro:
the operative part being simply:
And this produced nice little pdf-files at the size of 22 KB, used it for years and years, never a problem.
Well, then I just switched to Excel 2016 (NOT lovely), and the above does not work, so made this instead:
simple, works too, BUT, now I get a pdf file of 245 KB !! And for several good reasons this is way too big for my use.
now, if I do the exact same thing manually, namely go to print, use pdfcreator, and save the file, I get a nice 22 KB file as before.
Why in God's name won't it do it from macro then????
So I decided to take another approach, and made this:
also does the job, but again I get a huge 245 KB file.
Anybody have any bright ideas??? I cannot use files that big, and having to do this manually (it's also a matter of getting the exact right filename and place to put it) is a huge drag.
Code:
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'
'Print the document to PDF
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"
'
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'
'Wait until the file shows up before closing PDF Creator
Do
DoEvents
Loop Until Dir(sPDFPath & sPDFName) = sPDFName
pdfjob.cClose
'
Set pdfjob = Nothing
the operative part being simply:
Code:
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"
And this produced nice little pdf-files at the size of 22 KB, used it for years and years, never a problem.
Well, then I just switched to Excel 2016 (NOT lovely), and the above does not work, so made this instead:
Code:
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator", PrintToFile:=True, PrToFileName:=sPDFPath & sPDFName
simple, works too, BUT, now I get a pdf file of 245 KB !! And for several good reasons this is way too big for my use.
now, if I do the exact same thing manually, namely go to print, use pdfcreator, and save the file, I get a nice 22 KB file as before.
Why in God's name won't it do it from macro then????
So I decided to take another approach, and made this:
Code:
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=sPDFPath & sPDFName, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
also does the job, but again I get a huge 245 KB file.
Anybody have any bright ideas??? I cannot use files that big, and having to do this manually (it's also a matter of getting the exact right filename and place to put it) is a huge drag.