ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Hi,
Currently when i save my excel sheet as pdf i use this line of code.
So the above is saved like so INVOICE 1.pdf
Now i wish to include the date so the above becomes INVOICE 1 27/03/2024.pdf
So i added this extra piece of code to the previous mentioned above so now like so.
But when i now go to save i get a RTE 1004 & the line below is shown in yellow
FULL CODE.
Currently when i save my excel sheet as pdf i use this line of code.
VBA Code:
strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\PAUL GODDARD\" & "INVOICE " & Range("L4").Value & ".pdf"
So the above is saved like so INVOICE 1.pdf
Now i wish to include the date so the above becomes INVOICE 1 27/03/2024.pdf
So i added this extra piece of code to the previous mentioned above so now like so.
Rich (BB code):
strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\PAUL GODDARD\" & "INVOICE " & Range("L4").Value & Range("L13").Value & ".pdf"
But when i now go to save i get a RTE 1004 & the line below is shown in yellow
FULL CODE.
Rich (BB code):
Private Sub Generate_Pdf_Click()
Dim strFileName As String
strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\PAUL GODDARD\" & "INVOICE " & Range("L4").Value & Range("L13").Value & ".pdf"
If Dir(strFileName) <> vbNullString Then
MsgBox "GENERATED PDF INVOICE" & vbNewLine & vbNewLine & "INVOICE " & 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 & "INVOICE " & Range("L4").Value & vbNewLine & vbNewLine & "WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE")
Range("L4").Value = Range("L4").Value + 1 'INVOICE IS INCREMATED BY 1
ActiveWorkbook.Save
End With
End Sub
Last edited by a moderator: