Hi,
I am trying to save an Excel worksheet in pdf format in a specific folder. Below is the code:
Code:
Sub SaveInvoice()
Dim fName As Variant, strPathLocation As String
If Month(Date) > 6 And Month(Date) < 13 Then
strPathLocation = "D:\Elegance Acctng\Elegance Acctng_Financial Records_" & Format(Date, "yyyy") & "-" _
& Format(Date, "yy") + 1 & "\Tax Invoices Storage_" & Format(Date, "yyyy") & "-" & Format(Date, "yy") + 1 & "\"
ElseIf Month(Date) > 0 And Month(Date) < 7 Then
strPathLocation = "D:\Elegance Acctng\Elegance Acctng_Financial Records_" & Format(Date, "yyyy") - 1 & "-" _
& Format(Date, "yy") & "\Tax Invoices Storage_" & Format(Date, "yyyy") - 1 & "-" & Format(Date, "yy") & "\"
End If
fName = Application.InputBox("Type Invoice Number") 'Application.InputBox is a method not a function
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPathLocation & fName
End Sub
In this code the path where the document will be saved is:
D:\Elegance Acctng\Elegance Acctng_Financial Records_2019-20\Tax Invoices Storage_2019-20\, and the code is perfect since it is giving the right path. However, when the code reaches the last line I get this error:
"Run-time error 1004
Document not saved. The document may be open, or an error may have been encountered when saving"
I don't know what the error is and why it is happening since the directory path is correct.
Any help would be appreciated.
Thank you
Khalil