I have this VBA code to save the active sheet as PDF file:
Dim fName As String
fName = Range("E1").Value
ChDir "C:\Users\sally\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\sally\Desktop\Daily Department Report- " & fName, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
I tried this com with my com and the code works perfectly.
However, when I change to another computer, I changed the path name accordingly. Instead of sally (original computer user name), I changed it to mary. Please see the new code:
Dim fName As String
fName = Range("E1").Value
ChDir "C:\Users\mary\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\mary\Desktop\Daily Department Report- " & fName, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
At this point, when I try to run the code, it gives me this error message:
Run-time error 1004
Document not saved. The document may be open, or an error may have been encountered when saving.
Does anyone knows why?
Bookmarks