Saving Invoice using Customer name as PDF format

Jongnj87

New Member
Joined
Oct 16, 2020
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hi Sir, I using this code to do my invoice

Sub SaveInvoiceAsPDFAndClear()
Dim NewFN As Variant
NewFN = "C:YY\Invoice" & Range(H3").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
Range(H3").Value = Range(H3").Value + 1
Range(C13:F23").ClearContents
End Sub

However, I would like to using my customer name instead of invoice number. My customer name is in cell B7. How do I edit it??
 
Maybe this:

VBA Code:
Option Explicit
Sub SaveInvoiceAsPDFAndClear()
    
    Dim NewFN As Variant
    Dim wsSourceTab As Worksheet
    
    Application.ScreenUpdating = False
    
    Set wsSourceTab = ThisWorkbook.Sheets("Sheet1") 'Name of sheet in the current workbook with the invoice data. Change to suit.
    
    NewFN = "C:\YY\Invoice\" & wsSourceTab.Range("B7").Value & ".pdf"
    wsSourceTab.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    With wsSourceTab
        .Range("H3").Value = .Range("H3").Value + 1
        .Range("C13:F23").ClearContents
    End With
    
    Application.ScreenUpdating = True

End Sub

Just change the "wsSourceTab" variable to suit.
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Maybe this:

VBA Code:
Option Explicit
Sub SaveInvoiceAsPDFAndClear()
   
    Dim NewFN As Variant
    Dim wsSourceTab As Worksheet
   
    Application.ScreenUpdating = False
   
    Set wsSourceTab = ThisWorkbook.Sheets("Sheet1") 'Name of sheet in the current workbook with the invoice data. Change to suit.
   
    NewFN = "C:\YY\Invoice\" & wsSourceTab.Range("B7").Value & ".pdf"
    wsSourceTab.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    With wsSourceTab
        .Range("H3").Value = .Range("H3").Value + 1
        .Range("C13:F23").ClearContents
    End With
   
    Application.ScreenUpdating = True

End Sub

Just change the "wsSourceTab" variable to suit.

Thank you sir, will try this later
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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