Reputation: 15
I have a problem with creating a PDF with a button in Excel (VBA).
We have this code:
Sub pdf_drucken2()
ChDir "C:\Users\Name"
Worksheets("LaptopReport").ExportAsFixedFormat Type:=x1TypePDF, Filename:= _
"C:\Users\Name\test213.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
I would like to create this PDF on every computer. When I send this Excel Sheet to someone, he should be able to create the PDF as well. So is there a way I can create a PDF without specifying a path like "C:\Users\Name\test.pdf"?
Upvotes: 1
Views: 29
Reputation: 11755
You can use environment variables to get the username:
Filename:= "C:\Users\" & Environ$("UserName") & "\Desktop\test213.pdf"
Upvotes: 2