Need Macro to print selected area(s) to PDF using a file name in cell

rcicconetti

New Member
Joined
Jan 16, 2016
Messages
34
I have created a scheduling sheet.

I would like to select (days of the week) X3:AC52, AE3:AJ52, AL3:AQ52, AS3:AX52, AA59:AF111, AH59:AM111 and AO59:AT111 to save as a PDF.

I want to name the PDF whatever value is currently located in AE2 (ie Week of Jan1).

I would like to save it to a folder "Schedules" in C:\User\Owner\Documents\Schedules.

The PDF should save as 7 pages in the PDF file (one for each selection).

Thanks for any help
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this:
Code:
Public Sub Create_PDF()
     
    Dim saveFileName As String
    Dim PDFranges As Range
    
    With ActiveSheet
        saveFileName = "C:\User\Owner\Documents\Schedules\" & .Range("AE2").Value & ".pdf"
    
        Set PDFranges = .Range("X3:AC52,AE3:AJ52,AL3:AQ52,AS3:AX52,AA59:AF111,AH59:AM111,AO59:AT111")
    End With
    
    PDFranges.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveFileName, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
     
End Sub
I'm not sure if you want the save folder to depend on the user (computer) running the code, in which case use the path returned by CreateObject("WScript.Shell").SpecialFolders("MyDocuments") instead of the ""C:\User\Owner\Documents" part of the file name.
 
Upvote 0
I got a Run-time error'1004':
"Document not saved. The document may be open, or an error may have been encountered when saving."

Debugger highlighted line:
"PDFranges.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveFileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True"
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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