PDF create button in excel
Hi,
I have a button in my sheet which creates a PDF of the sheet and saves it to the users desktop. The name of the PDF is just the name of the excel file. I found that if the button is pushed twice without moving or renaming the PDF after the first push I get an error.
How would I enable a user to choose the location and name for the PDF?
The code:
Code:
Sub Button2336_Click()
'
' Button2336_Click Macro
'
'
ChDir "C:\Users\" & Environ("Username") & "\desktop\"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filesavename, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End Sub
Thanks for any help!
Re: PDF create button in excel
If I change;
Filename:=filesavename, _
to
Filename:=InputBox("Enter file name"), _
it lets you choose a file name and works the first time with no problems. The second time you push the button and select a different name it creates the PDF but displays a runtime error. Any ideas?
Re: PDF create button in excel
Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.
Re: PDF create button in excel