print pdf with tab as file name

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
675
Office Version
  1. 365
Platform
  1. Windows
hi,

is it possible to print the in sheet1 , sheet3 & sheet2 (in that order) save as their tab names to the following locations:-

sheet1 = c:\data

(print area is A1:I23

sheet3 = c:\data2

(print area is A1:O15

sheet2 = c:\data3

(print area is A1:H22)

and print each as a PDF?

Please can some kind code 'guru' sort for me as I am desperate.

MTIA
Trevor3007
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try...

Code:
Sub ExportSheetsToPDF()

    Dim vFolders As Variant
    Dim vSheetNames As Variant
    Dim vPrintAreas As Variant
    Dim i As Long
    
    vFolders = Array("C:\Data", "C:\Data2", "C:\Data3")
    vSheetNames = Array("Sheet1", "Sheet2", "Sheet3")
    vPrintAreas = Array("A1:I23", "A1:O15", "A1:H22")
    
    For i = LBound(vSheetNames) To UBound(vSheetNames)
        With Worksheets(vSheetNames(i))
            .PageSetup.PrintArea = vPrintAreas(i)
            .ExportAsFixedFormat Type:=xlTypePDF, Filename:=vFolders(i) & "\" & vSheetNames(i) & ".pdf", IgnorePrintAreas:=False, OpenAfterPublish:=False
        End With
    Next i
    
End Sub

Hope this helps!
 
Upvote 0
Try...

Code:
Sub ExportSheetsToPDF()

    Dim vFolders As Variant
    Dim vSheetNames As Variant
    Dim vPrintAreas As Variant
    Dim i As Long
    
    vFolders = Array("C:\Data", "C:\Data2", "C:\Data3")
    vSheetNames = Array("Sheet1", "Sheet2", "Sheet3")
    vPrintAreas = Array("A1:I23", "A1:O15", "A1:H22")
    
    For i = LBound(vSheetNames) To UBound(vSheetNames)
        With Worksheets(vSheetNames(i))
            .PageSetup.PrintArea = vPrintAreas(i)
            .ExportAsFixedFormat Type:=xlTypePDF, Filename:=vFolders(i) & "\" & vSheetNames(i) & ".pdf", IgnorePrintAreas:=False, OpenAfterPublish:=False
        End With
    Next i
    
End Sub

Hope this helps!

hi domenic,

thanks for your help. I ran it but received 2 errors.

https://www.amazon.co.uk/clouddrive/share/S114twkG1LK19n95fPRQrAlfoOEkcsJc0xe3FzcUZnL

please see link above for more info.

KR
Trevor3007
 
Upvote 0
Can you post the exact code that you're using, and state which line or lines the errors occur?
 
Upvote 0
Can you post the exact code that you're using, and state which line or lines the errors occur?


hi,

I am using the code you sent & the errors dont show which line ...only the error messages are displayed.


Sorry :[

KR
Trevor
 
Upvote 0
You've made no changes whatsoever? As it stands, the code generates no errors. I can't reproduce your errors.
 
Upvote 0
You've made no changes whatsoever? As it stands, the code generates no errors. I can't reproduce your errors.

hi,

slight change to the save path... but thats all!!! very odd.

I will try again & get back to you if i mange to sort


thanks anyhoos
 
Upvote 0
I don't think those sheet names should be a problem. If you named your sheets in your new workbook with those same names do you still get an error?
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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