Macro to loop through sheets with a start point

samokell

New Member
Joined
Dec 18, 2019
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have the following macro, that just publishes every sheet in PDF:

Sub ExportToPDFs()
Dim ws As Worksheet

For Each ws In Worksheets
ws.Select
nm = ws.Name

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Exports\" & nm & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False

Next ws

End Sub


However, I have about 20 sheets before the point I'd like to start publishing from:

So, I'd like this to loop through every sheet, but only AFTER the sheet called "Template - FX Only"

Any ideas?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi,
welcome to forum

Untested but see if update to your code does what you want

VBA Code:
Sub ExportToPDFs()
    Dim i As Integer
    Dim nm As String
    
    
    For i = Worksheets("Template - FX Only").Index + 1 To Worksheets.Count
        nm = Worksheets(i).Name
        Worksheets(i).ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\Exports\" & nm & ".pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
    
    Next i

End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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