Home » excel » store excel sheet as PDF on desktop

store excel sheet as PDF on desktop

Posted by: admin May 14, 2020 Leave a comment


I have the following code to store a sheet as PDF. And I would like to control where it is stored – i.e. their desktop. Can some one give me a tip how to do that pls. Thanks!

Sub SaveAsPDF()
Dim i As Long
Dim PdfFile As String, Title As String

' Not sure for what the Title is
Title = Range("B1")

' Define PDF filename
PdfFile = Range("F3")
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & ".pdf"

' Export activesheet as PDF
With ActiveSheet
  .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With

End Sub
How to&Answers:

An alternative to Rory’s answer, could be the use of the windows environment variable “userprofile”

PdfFile = Environ("userprofile") & "\desktop\" & PdfFile & ".pdf"


If you always want to save to the Desktop without any user intervention:

PdfFile = createobject("Wscript.Shell").Specialfolders("Desktop") & "\" & PdfFile & ".pdf"