Macro - Only PDF tabs that are green?

Shaylena

New Member
Joined
Jan 10, 2018
Messages
3
Hey all,

I currently have a macro that will go through all the tabs in my worksheet, export them to pdfs, rename, and save them to a certain location.

However, I was wondering if it would be possible to only target pdf tabs that are a certain color.
IE - PDF all tabs that are green and ignore all other tabs. Here is the code that I have so far:

Sub ExportToPDFs()
' PDF Export Macro
' Change C:\Exports\ to your folder path where you need the files are saved
' Save Each Worksheet to a separate PDF file.

Dim ws As Worksheet

For Each ws In Worksheets
ws.Select
nm = ws.Name
mn = "_01.31.18"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="File location" & nm & mn & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False

Next ws

End Sub

Any suggestions?

Thanks in advance!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi & welcome to the board.
How about
Code:
Sub ExportToPDFs()
' PDF Export Macro
' Change C:\Exports\ to your folder path where you need the files are saved
' Save Each Worksheet to a separate PDF file.

   Dim ws As Worksheet
   Dim nm, mn
   For Each ws In Worksheets
      If ws.Tab.Color = [COLOR=#ff0000]5287936 [/COLOR]Then
         ws.Select
         nm = ws.Name
         mn = "_01.31.18"
         
         ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
         fileName:="File location" & nm & mn & ".pdf", _
         Quality:=xlQualityStandard, IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, OpenAfterPublish:=False
      End If
   Next ws

End Sub
Change the value in red to match the tab colour
 
Upvote 0
Hi & welcome to the board.
How about
Code:
Sub ExportToPDFs()
' PDF Export Macro
' Change C:\Exports\ to your folder path where you need the files are saved
' Save Each Worksheet to a separate PDF file.

   Dim ws As Worksheet
   Dim nm, mn
   For Each ws In Worksheets
      If ws.Tab.Color = [COLOR=#ff0000]5287936 [/COLOR]Then
         ws.Select
         nm = ws.Name
         mn = "_01.31.18"
         
         ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
         fileName:="File location" & nm & mn & ".pdf", _
         Quality:=xlQualityStandard, IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, OpenAfterPublish:=False
      End If
   Next ws

End Sub
Change the value in red to match the tab colour

That worked perfectly, thank you so much for your help!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,039
Latest member
Mbone Mathonsi

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