Hi,
Currently I am using the below code to generate new invoice number like A2B-1001 where A2B-1000 is already put in cell F2. When i trigger this macro it clears certain cells and changes the value in F2 to A2B-1001.
This is done with the following line in the attached code:
Range("F2").Value = Left(Range("F2").Value, 4) & 1 + Mid(Range("F2").Value, 5, 4)
Sub SaveInvoiceAsPDFAndMailAndClear()
Dim NewFN As Variant
With Application
.ScreenUpdating = False
.EnableEvents = False
.Application.DisplayAlerts = False
End With
NewFN = "H:\Others\Invoices\INV-" & Range("F2").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=NewFN, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
If ActiveSheet.Range("J2").Value <> 0 Then
With CreateObject("outlook.application").CreateItem(0)
.To = ThisWorkbook.Sheets("Invoice").Range("J2").Value
.Subject = "Delivery Invoice"
.Body = "Dear " & ThisWorkbook.Sheets("Invoice").Range("E4").Value & "," & vbCrLf & "" & vbCrLf & "Hope You are fine." & vbCrLf & "" & vbCrLf & "Your Parcel is on the way." & vbCrLf & "Please see the attached file for the latest Delivery Invoice. " & vbCrLf & "" & vbCrLf & "Thank you for being with us." & vbCrLf & "" & vbCrLf & "Regards," & vbCrLf & "Admin,"
.attachments.Add NewFN
.Send
End With
Else
MsgBox ("Mail Address not found." & vbCrLf & "File will be saved in Invoices Folder.")
Cancel = True
End If
Range("F2").Value = Left(Range("F2").Value, 4) & 1 + Mid(Range("F2").Value, 5, 4)
Range("E4,C9,F12,F24,F25").ClearContents
End Sub
But I need the invoice number to be like YYMMDDNNN where NNN will change like 001, 002, 003 etc invoices made on same date.
This forum is of great help & I hope that I will not be disappointed.
Thanks in advance.
Bookmarks