pdf macro

redskifreak

New Member
Joined
Mar 28, 2013
Messages
2
I have copied this macro from one of your previous threads for making an invoice with increasing invoice number. I want the document to save as a PDF instead of an excel document.

Sub NextInvoice()
Range("i8").Value = Range("i8").Value + 1
Range("b21:h34").ClearContents
Range("b8:b10").ClearContents
End Sub
Sub SaveInvWithNewName()
Dim NewFN As Variant
' Copy Invoice to a new workbook
ActiveSheet.Copy
NewFN = "C:\Users\Jean\Desktop\Caramelized cook\" & Range("b8").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
NextInvoice
End Sub

I have changed the .xlsx extention to .pdf and it saves as a pdf but when i try to open it it gives me the error message "that it is either not a supported file or because the file has been damaged (for example it was sent as an email attachment was not correctly decoded)"

I am a macro newbie and would apperiacte some advise. Thank you in advance.
(don't mind my spelling)
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I think this just above either "' Copy Invoice to a new workbook" or NextInvoice should do it.

Code:
NewFNpdf = "C:\Users\Jean\Desktop\Caramelized cook\" & Range("b8").Value & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=NewFNpdf, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False
 
Upvote 0
inserted just above "copy invoice to new workbook" worked perfectly! saves a copy as a PDF and a copy as an excel sheet.

Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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