vbanoob1234
New Member
- Joined
- Aug 8, 2016
- Messages
- 26
Hello everyone,
I am having difficulties. I have a workbook with several worksheets, Sheet 1, Sheet 2, Sheet 3.
But some workbooks have Sheet 3 missing, so therefore I want my macro to skip that worksheet and continue.
Here is what I got so far.
Sub SpecficSheets()
Dim wb As Workbook, ws As Worksheet
Dim sFil As String, sPath As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet
sPath = "C:Desktop\Print All" 'location of files
sFil = Dir(sPath & "*.xlsx") 'change or add formats
Application.DisplayAlerts = False
Do Until sFil = ""
Workbooks.Open sPath & sFil
Set wb = ActiveWorkbook
'ws to set recon page to one
With Worksheets("T3 Class").PageSetup
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
'ws.PrintOut
wb.Sheets(Array("Sheet 1", "Sheet 2", "Sheet 3")).Select
wb.Worksheets(Array("Sheet 1", "Sheet 2", "Sheet 3")).PrintOut
wb.Close
sFil = Dir()
Loop
Application.DisplayAlerts = True
End Sub
I am having difficulties. I have a workbook with several worksheets, Sheet 1, Sheet 2, Sheet 3.
But some workbooks have Sheet 3 missing, so therefore I want my macro to skip that worksheet and continue.
Here is what I got so far.
Sub SpecficSheets()
Dim wb As Workbook, ws As Worksheet
Dim sFil As String, sPath As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet
sPath = "C:Desktop\Print All" 'location of files
sFil = Dir(sPath & "*.xlsx") 'change or add formats
Application.DisplayAlerts = False
Do Until sFil = ""
Workbooks.Open sPath & sFil
Set wb = ActiveWorkbook
'ws to set recon page to one
With Worksheets("T3 Class").PageSetup
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
'ws.PrintOut
wb.Sheets(Array("Sheet 1", "Sheet 2", "Sheet 3")).Select
wb.Worksheets(Array("Sheet 1", "Sheet 2", "Sheet 3")).PrintOut
wb.Close
sFil = Dir()
Loop
Application.DisplayAlerts = True
End Sub