Help to create code with specific name

flyinghigher2014

New member
Joined
May 12, 2016
Messages
13
Reaction score
0
Points
0
Hi Everyone

ive attached a picture of something id like to do. i save invoices as a pdf and what i would like to be able to do is incorporate the client ID and invoice number and when i click save to pdf it combines the two bits of information and adds that as the file name when saving.

invoice number is in cell N14 and the client id is in N15.

below is my safe to pdf code.

Code:
'Print the invoice to PDFSub PrintPDFInvoice()
'turn off screenupdating
Application.ScreenUpdating = False


If Range("N13") = "" Then
MsgBox "Please Enter The Invoice Date"
Exit Sub


ElseIf Range("N16") = "" Then
MsgBox "Please Enter The Start Date For Your Contract Hire"
Exit Sub


ElseIf Range("N17") = "" Then
MsgBox "Please Enter The End Date For Your Contract Hire"
Exit Sub


ElseIf Range("G12") = "" Then
MsgBox "Please add the company"
Exit Sub


End If
'open dialog and set file type
Opendialog = Application.GetSaveAsFilename("", filefilter:="PDF Files (*.pdf), *.pdf", _
Title:="Your Invoice")
'if no value is added for file name
If Opendialog = False Then
MsgBox "not successful"
Exit Sub
End If
'set the named range for the PDF
Set MyRange = Sheet2.Range("G6:N54")
Sheet2.PageSetup.PrintArea = "G6:N54"
'create the PDF
On Error Resume Next
MyRange.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=Opendialog, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
On Error GoTo 0
'clear the page breaks
ActiveSheet.DisplayPageBreaks = False
Application.ScreenUpdating = False




End Sub
 

Attachments

  • Save invoice.jpg
    Save invoice.jpg
    17.3 KB · Views: 9
To maximize your chances of getting an answer always try to post in the most adequate forum.

This question being clearly VBA related, it should have been posted there. I moved it for you.

Perhaps posting your sheet would also help the VBA savvy members? ( no pics please)
 
Back
Top