Saving an invoice with an Invoice number and Customer Name

mohammed_chand

New Member
Joined
Oct 30, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
i have following code in my Module.
currently code saves invoices with invoice number. however i would like to add customer name with invoice number.
Invoice number is in D5 and customer name is in B11.
i would appreciate your help on this. how do i tweak my code to get customer name with invoice number.

Sub SaveInvoiceBothWaysAndClear()
Dim NewFN As Variant
' Create the PDF First
NewFN = "C:\Users\User\Desktop\invoice\" & Range("D5").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
' Next, Save the Excel File
ActiveSheet.Copy
NewFN = "C:\Users\User\Desktop\invoice\" & Range("D5").Value & ".xlsx"
ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close
Range("D5").Value = Range("D5").Value + 1
Range("A14:C23").ClearContents
Range("B11").ClearContents
Range("A11").ClearContents
ActiveWorkbook.Close SaveChanges:=True
End Sub
 
i have just checked and found out that there is an "enter" new line in customer name.
example, bc contractors, london. i have it as
bc contractors
london.
so i think best option would be to use first 3 letters of customer name. do i have to amend any part of the code to use just first 3 letters of customer name?
Yes, that is an illegal character you cannot have in a file name.
Simply use the LEFT function on that part of the formula:

Rich (BB code):
NewFN = "C:\Users\User\Desktop\invoice\" & Left(Range("B11").Value,3) & "_" & Range("D5").Value & ".xlsx"
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,213,489
Messages
6,113,947
Members
448,534
Latest member
benefuexx

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