Save Active Sheet as PDF in specific Directory

MindManagement

New Member
Joined
Jan 13, 2016
Messages
8
I found some code on the internet that saves your active sheet as a PDF in a specific directory. I compared the code I found on the internet figuratively speaking a thousand times but I can't see the error. Since I 'm new in the world of programmign macro's (I normally do record Macro), can anyone tell me where the code is wrong.
The error message I get is "run-time error '100' Application-defined or object-defined error". Below is the code as I can see it in my editor.

Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
'
ActiveSheet.ExportAsFixedFormat _
Type:=x1TypePDF, _
Filename:="G:\E-INVOICE" & ActiveSheet.Name, _
Quality:=x1QualityStandard, _
IncludeDocProperties:=False, _
IngnorePrintAreas:=False, _
OpenAfterPublish:=False

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You need an additional backslash to separate the directory and filename, and I usually include the file extension when setting the filename - see if this helps...

Filename:="G:\E-INVOICE\" & ActiveSheet.Name & ".pdf"
 
Upvote 0
Cod changed and still the same error :

Sub SaveAsPDF()
'
' SaveAsPDF Macro
'
'
ActiveSheet.ExportAsFixedFormat _
Type:=x1TypePDF, _
Filename:="G:\E-INVOICE" & ActiveSheet.Name & ".pdf", _
Quality:=x1QualityStandard, _
IncludeDocProperties:=False, _
IngnorePrintAreas:=False, _
OpenAfterPublish:=False

End Sub
 
Upvote 0
Well, being smart I recorded a macro and executed this macro and it works, except to 1 tiny thing.
The code looks like :
Sub SaveAs_PDF()
'
' SaveAs_PDF Macro
'
'
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"G:\E-INVOICE" & ActiveWorkbook.Name & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub

The excvel sheet is actually an Invoice layout and the workbook's name is 016-322 Deufol.xlss
016-322 : No. of Invoice
Deufol : The name of the company I Invoice.

Running the macro it works perfect, no errors, but it creates a file "016-322 Deufol.xlsx.pdf"

Of course I would like a filename "016-322 Deufol.pdf"
 
Upvote 0
Simply Change
ActiveWorkbook.Name

to Left(ActiveWorkbook.Name, LEN(ActiveWorkbook.Name) - 5)
 
Upvote 0
Woohoee It works perfectly. Saves me a lot of time and mouse clicks since I create dozen of invoices each day. Many thanks, my friend.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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