Print to PDF Excel Tabs

willbost

New Member
Joined
Jun 16, 2006
Messages
21
I have a workbook that has the following tabs:

Cover
DJones
ASmith
KAdams
etc....

There are actually 27 tabs with individual names of managers. I want to be able to save out 2 tabs together as a PDF for each name. Thus Cover & DJones, then Cover & ASmith, then Cover & KAdams, etc...

I am currently printing as PDF manually, but am looking for a more automated way. Thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try...

Code:
[FONT=Verdana][COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit[/COLOR][/FONT]
[COLOR=#00008b][/COLOR] 
[FONT=Verdana][COLOR=darkblue]Sub[/COLOR] CreatePDF()[/FONT]
 
[FONT=Verdana]   [COLOR=darkblue]Dim[/COLOR] strDestPath [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR][/FONT]
[FONT=Verdana]   [COLOR=darkblue]Dim[/COLOR] wkbSource [COLOR=darkblue]As[/COLOR] Workbook[/FONT]
[FONT=Verdana]   [COLOR=darkblue]Dim[/COLOR] wkbDest [COLOR=darkblue]As[/COLOR] Workbook[/FONT]
[FONT=Verdana]   [COLOR=darkblue]Dim[/COLOR] wks [COLOR=darkblue]As[/COLOR] Worksheet[/FONT]
 
[FONT=Verdana]   Application.ScreenUpdating = [COLOR=darkblue]False[/COLOR][/FONT]
[FONT=Verdana]   Application.DisplayAlerts = [COLOR=darkblue]False[/COLOR][/FONT]
 
[FONT=Verdana]   strDestPath = "C:\Users\Domenic\Desktop\"   [COLOR=green]'change the destination path accordingly[/COLOR][/FONT]
 
[FONT=Verdana]   [COLOR=darkblue]If[/COLOR] Right(strDestPath, 1) <> "\" [COLOR=darkblue]Then[/COLOR] strDestPath = strDestPath & "\"[/FONT]
 
[FONT=Verdana]   [COLOR=darkblue]Set[/COLOR] wkbSource = ActiveWorkbook[/FONT]
[FONT=Verdana]   wkbSource.Worksheets("Cover").Copy[/FONT]
 
[FONT=Verdana]   [COLOR=darkblue]Set[/COLOR] wkbDest = ActiveWorkbook[/FONT]
 
[FONT=Verdana]   [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] wks [COLOR=darkblue]In[/COLOR] wkbSource.Worksheets[/FONT]
[FONT=Verdana]       [COLOR=darkblue]If[/COLOR] wks.Name <> "Cover" [COLOR=darkblue]Then[/COLOR][/FONT]
[FONT=Verdana]           wks.Copy after:=wkbDest.Worksheets(1)[/FONT]
[FONT=Verdana]           wkbDest.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strDestPath & wks.Name & ".pdf"[/FONT]
[FONT=Verdana]           wkbDest.Worksheets(2).Delete[/FONT]
[FONT=Verdana]       [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR][/FONT]
[FONT=Verdana]   [COLOR=darkblue]Next[/COLOR] wks[/FONT]
 
[FONT=Verdana]   wkbDest.Close savechanges:=[COLOR=darkblue]False[/COLOR][/FONT]
 
[FONT=Verdana]   Application.ScreenUpdating = [COLOR=darkblue]True[/COLOR][/FONT]
[FONT=Verdana]   Application.DisplayAlerts = [COLOR=darkblue]True[/COLOR][/FONT]
 
[FONT=Verdana]   MsgBox "Completed...", vbInformation[/FONT]
 
[FONT=Verdana][COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]
 
Upvote 0
Thanks!!!! It worked like a charm. May be too good since it also printed hidden tabs with the cover tab.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

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