Hello all, II have a macro that whenever I run it, it save the file in PDF format with the date and a number, the files are invoices, I wrote a macro and it works nice except one thing. When I run the macro and it save the file for example witht the format invoice-130001-07/08/2014, (the PDF starts from 130000) and the 9th generated file that is the last generated file of the day has the name invoice-130009-07/08/2014 but but when I save it in the next day, logically it must be invoice-130010-08/08/2014 but it starts again from 130001 for the number and macro generates the name invoice-130001-08/08/2014 I want to know if there is anyway to fix it?
The code is here and the file is attached:
Code:
Sub quote13000()
'
Dim exdate As Date
Dim o As Object
Dim odoc As Document
Dim nm, nm1 As String
Dim i As Integer
Dim PathAndFileName As String, n As Long
Set odoc = ActiveDocument
n = 3000
PathAndFileName = "C:\Users\Tony\Documents\Quotes\Quote 1"
If Dir(PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf") = "" Then
nm = PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf"
With ActiveDocument
.SaveAs FileName:=nm, _
Fileformat:=wdFormatPDF
'.Close
End With
Else
n = 3000
Do While Dir(PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf") <> ""
n = n + 1
Loop
nm = PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf"
With ActiveDocument
.SaveAs FileName:=nm, _
Fileformat:=wdFormatPDF
' .Close
End With
End If
End Sub