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??
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi Jongnj87,

Welcome to MrExcel!!

Try changing the cell reference from H3 in this line...

NewFN = "C:YY\Invoice" & Range(H3").Value & ".pdf"

...to B7 like so:

NewFN = "C:YY\Invoice" & Range("B7").Value & ".pdf"

Note your code is also missing a set of quotation marks which I've also bolded.

Thanks,

Robert
 
Upvote 0
.
And there is a FORWARD SLASH missing as well in the PATH :

NewFN = "C:\YY\Invoice" & Range("B7").Value & ".pdf"
 
Upvote 0
.
And there is a FORWARD SLASH missing as well in the PATH :

NewFN = "C:\YY\Invoice" & Range("B7").Value & ".pdf"

Thanks you it help. However 1 this is why the pdf file only save at YY and not into Invoice
 
Upvote 0
Hi Jongnj87,

Welcome to MrExcel!!

Try changing the cell reference from H3 in this line...

NewFN = "C:YY\Invoice" & Range(H3").Value & ".pdf"

...to B7 like so:

NewFN = "C:YY\Invoice" & Range("B7").Value & ".pdf"

Note your code is also missing a set of quotation marks which I've also bolded.

Thanks,

Robert

Yes it help. Thank you but why does the file only save at YY and not into Invoice??
 
Upvote 0
You need another backslash:

NewFN = "C:YY\Invoice\" & Range("B7").Value & ".pdf"
 
Upvote 0
You need another backslash:

NewFN = "C:YY\Invoice\" & Range("B7").Value & ".pdf"

Sir, 1 last question. I'm doing this code on a single workbook. However, I got another workbook which all my master list. Am I possible to create this Code on the sheet itself???
 
Upvote 0
Sorry - I'm not too sure what you mean :confused:

You can put the code on the sheet as an event macro so it will run after an event happens (like a cell change). So that what you want?
 
Upvote 0
Sorry - I'm not too sure what you mean :confused:

You can put the code on the sheet as an event macro so it will run after an event happens (like a cell change). So that what you want?
Hmmmm.

This invoice is 1 workbook. I trying to use this code on the master list workbook on 1 of the sheet. So that I don't have to open 2 workbooks.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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