Save generated pdf as speciac name then invoice number

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Afternon,

I am using the code shown below to save the generated file as a pdf.
It takes the value from cell L4

So the generated saved file is just shown / called as 1,2,3 etc etc

Please can you advise how i insert into the code the word RECEIPT

I did try & RECEIPT where ive shown in Red but kept getting error messages.

Then the saved pdf will be saved like RECEIPT 1 RECEIPT 2 RECEIPT 3

Thanks

Rich (BB code):
Private Sub Generate_Pdf_Click()
    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR\GM PRODUCTIONS\" & Range("L4").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GENERATED PDF INVOICE" & vbNewLine & vbNewLine & Range("L4").Value & vbNewLine & vbNewLine & "WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly, "GENERATE PDF FILE MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .PageSetup.PrintArea = "$F$2:$N$61"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        pdf = MsgBox("GENERATED PDF INVOICE " & Range("L4").Value & vbNewLine & vbNewLine & "WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE")
                                
        ActiveWorkbook.Save
        
    End With
        Range("L4").Value = Range("L4").Value + 1
        Range("G27:L36").ClearContents
        MsgBox "TEMPLATE CELLS HAVE NOW BEEN CLEARED", vbInformation, "CLEAR DESCRIPTION CELLS MESSAGE"
        Range("G27").Select
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try:
VBA Code:
Private Sub Generate_Pdf_Click()
    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR\GM PRODUCTIONS\" & "RECEIPT " & Range("L4").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GENERATED PDF INVOICE" & vbNewLine & vbNewLine & "RECEIPT " & Range("L4").Value & vbNewLine & vbNewLine & " WAS NOT SAVED AS IT ALLREADY EXISTS.", vbCritical + vbOKOnly, "GENERATE PDF FILE MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .PageSetup.PrintArea = "$F$2:$N$61"
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
        pdf = MsgBox("GENERATED PDF INVOICE" & vbNewLine & vbNewLine & "RECEIPT " & Range("L4").Value & " WAS SAVED SUCCESSFULLY.", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE")
                                
        ActiveWorkbook.Save
        
    End With
        Range("L4").Value = Range("L4").Value + 1
        Range("G27:L36").ClearContents
        MsgBox "TEMPLATE CELLS HAVE NOW BEEN CLEARED", vbInformation, "CLEAR DESCRIPTION CELLS MESSAGE"
        Range("G27").Select
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,837
Messages
6,121,883
Members
449,057
Latest member
Moo4247

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