• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

PDF Export

Dear Experts!

Can you please let me know where am I wrong with my coding? I am not able to run this macro. I think it happened when I inserted InvNo in between the codes.

Code:
 Option Explicit
Public Sub PDFexport1()
Dim PdfPath As String
Dim InvNo As String

InvNo = Worksheets("01Q").Range("E17").Value


ThisWorkbook.Sheets(Array("01Q", "Alstom IT Clinic QAR", "IT")).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    Worksheets("Macro").Range("L13") & "\" & "Alstom Invoices" & InvNo & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
     IgnorePrintAreas:=False, OpenAfterPublish:=False

PdfPath = Worksheets("Macro").Range("L13") & "\" & "Alstom Invoices" & InvNo & ".pdf"

Worksheets("SummaryTemp").Range("A1").Value = PdfPath

End Sub
 
Last edited:
Instead of using the likes of:
Worksheets("Macro").Range("L13") & "\" & "Alstom Invoices" & InvNo & ".pdf"
twice, use it once. It saves editing in two places and is a bit more robust:
Code:
Public Sub PDFexport1()
Dim PdfPath As String
Dim InvNo As String

InvNo = Worksheets("01Q").Range("E17").Value
ThisWorkbook.Sheets(Array("01Q", "Alstom IT Clinic QAR", "IT")).Select
PdfPath = Worksheets("Macro").Range("L13") & "\" & "Alstom Invoices" & InvNo & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Worksheets("SummaryTemp").Range("A1").Value = PdfPath
End Sub

To come to the question, what error are you getting, and what line is highlighted when you click the Debug button?
It could be worth checking what ends up in the variable InvNo to check that you're not trying to generate an illegal file name.
 
Its fine now. Macro was picking a date and as it won't allow the characters "*","/" as file name I changed the date format on the coding and fixed it.Thanks!
 
Back
Top