Dimitri de Ruiter
Dimitri de Ruiter

Reputation: 745

store excel sheet as PDF on desktop

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

Upvotes: 1

Views: 87

Answers (2)

Andreas N.
Andreas N.

Reputation: 246

An alternative to Rory's answer, could be the use of the windows environment variable "userprofile"

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

Upvotes: 1

Rory
Rory

Reputation: 34075

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

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

Upvotes: 2

Related Questions