简体   繁体   中英

Export the Excel Range into PDF

I have been using this below code to save the range as pdf but it does not save it as pdf neither gives an error.

Sub ExportAsPDF()
'Varriables
Dim SaveRng As Range
Dim pdfname As String
Dim path As String

'Setting range to be saved
Set SaveRng = Sheet2.Range("A1:D13")

'setting file name with a cell value
pdfname = Sheet2.Range("C1")

'path
path = "C:\Users\Jamini\Pictures"

'save the range as pdf
SaveRng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=path & pdfname & ".pdf"


End Sub

Try inserting the path separator as:

Filename:=path & "\" & pdfname & ".pdf"

Or build the path ending in path separator, in this way:

path = "C:\Users\Jamini\Pictures\"

And Warcupine is right, I think. You should find the created pdf in "C:\Users\Jamini" folder, but named as "Pictures" & pdfname & ".pdf" ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM