My macro worked correctly for a long time, suddenly stopped and displaying this error.
"Run time 1004: Document not saved. The document may be open, or an error may have been encountered when saving."
Highlighting this part (Sheet3.Range("A1:j46").ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=True, OpenAfterPublish:=True)
Could someone please show me where the error is?
Private Sub cmdSavePDS_Click()
Dim path As String
Dim fname As String
Dim invName As String
ThisWorkbook.Save
With Sheet3
invName = .Range("A13").Value & "-" & .Range("I7").Value
End With
invName = Replace(invName, "/", "_")
path = "C:\Anita\Invoices\"
Call MkDir(path)
path = path & "Invoices 2019\" '
Call MkDir(path)
path = path & Sheet3.Range("A13").Value
Call MkDir(path)
fname = path & "\" & invName
Sheet3.Range("A1:j46").ExportAsFixedFormat Type:=xlTypePDF, Filename:=fname, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=True, OpenAfterPublish:=True
' para abrir o arquivo coloque True em OpenAfterPublish
End Sub
'requires reference to Microsoft Scripting Runtime
Function MkDir(strDir As String)
Dim fso As New FileSystemObject
If Not fso.FolderExists(strDir) Then
' doesn't exist, so create the folder
fso.CreateFolder strDir
End If
End Function