MikeyW1969
Board Regular
- Joined
- Apr 28, 2014
- Messages
- 80
Hello,
I am creating a worksheet that I want to export as a pdf when I am finished. I want it to go into the current directory, but it is dropping into "My Documents" in one way and one directory up in the second version. I could get around the thing in the second version, but it is also adding the file name to the final pdf, which I don't want. Here is the two versions of the code I'm using.
This version names it correctly, the word Invoice, followed by the Invoice # from the cell where that appears, and the name of the user. But it puts it in the "My Documents" folder, no matter where I am working from.
This is the second version:
This one puts it one level above where I am actually working, which isn't a deal breaker, but it puts the actual original file name out in front of "Invoice", which I don't want. I want to leave the file path as the working location, because I plan to be able to access this anywhere, using Cloud storage, so I can generate these on the fly. I don't want to use a hard coded location on my computer, because that means that I can't generate these unless I am tied down in front of my desk at home.
Any ideas?
I am creating a worksheet that I want to export as a pdf when I am finished. I want it to go into the current directory, but it is dropping into "My Documents" in one way and one directory up in the second version. I could get around the thing in the second version, but it is also adding the file name to the final pdf, which I don't want. Here is the two versions of the code I'm using.
Code:
Sub CommitAndSave()
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="Invoice" & Range("B5") & "_" & Range("A8"), _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True
End Sub
This version names it correctly, the word Invoice, followed by the Invoice # from the cell where that appears, and the name of the user. But it puts it in the "My Documents" folder, no matter where I am working from.
This is the second version:
Code:
Sub CommitAndSave()
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "Invoice" & Range("B5") & "_" & Range("A8"), _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True
End Sub
This one puts it one level above where I am actually working, which isn't a deal breaker, but it puts the actual original file name out in front of "Invoice", which I don't want. I want to leave the file path as the working location, because I plan to be able to access this anywhere, using Cloud storage, so I can generate these on the fly. I don't want to use a hard coded location on my computer, because that means that I can't generate these unless I am tied down in front of my desk at home.
Any ideas?