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
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"