Macro to Save as Adobe PDF

raysha22

New Member
Joined
Nov 28, 2017
Messages
16
Hello!

I am trying to incorporate a button to save a selection to a PDF. If I do it manually, I use the option that says "Save as Adobe PDF". I have tried several different macros online for this and cannot get any of them to work. Any help would be great!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Option Explicit
Dim SvNm As String

Sub SaveAsPDF()
On Error GoTo EH

[COLOR=#0000ff]SvNm = InputBox(Prompt:="Enter file name to use when saving", Title:="Enter Save Name", Default:="Enter Filename here...")[/COLOR]
[COLOR=#ff0000]SvNm = Range("A1") 'change range to wherever the save name is in your file[/COLOR]

Application.PrintCommunication = True
    ChDir "[COLOR=#008000]C:\Users\JoeBloggs\Desktop\[/COLOR]"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "[COLOR=#008000]C:\Users\JoeBloggs\Desktop\[/COLOR]" & SvNm & ".pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:= _
        [COLOR=#ffa500]True [/COLOR]'change this to [COLOR=#ffa500]False[/COLOR] if you don't want to open it automatically

Range("J25").Select 'simply selects another desired cell when finished

Exit Sub

EH:
MsgBox ("File not saved, no filename was entered")
Range("J25").Select

End Sub

colour coding;
This allows you to enter a name via an input box. (put an ' before the one you don't want to use or delete)
This allows you to use cell contacts as a name. (put an ' before the one you don't want to use or delete)
Enter your filepath for saving

Hope this helps you out,

Coops
 
Last edited:
Upvote 0
I keep getting "Document not saved. the document may be open, or an error may have been encountered when saving" and then I get the error message at the end of the code.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top