Option Explicit
Const sSHEET1_NAME As String = "Sheet1"
Const sSHEET2_NAME As String = "Sheet2"
Sub PrintWorksheets()
Dim wb As Workbook
Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim sPath As String
Dim sExtension As String
Dim sFile As String
Dim SelectFolder As FileDialog
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'Retrieve Target Folder Path From User
Set SelectFolder = Application.FileDialog(msoFileDialogFolderPicker)
With SelectFolder
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
sPath = .SelectedItems(1) & "\"
End With
'In Case of Cancel
NextCode:
sPath = sPath
If sPath = "" Then GoTo CleanUp
'Target File Extension (must include wildcard "*")
sExtension = "*.xls*"
'Target Path with Ending Extention
sFile = Dir(sPath & sExtension)
'Loop through each Excel file in folder
Do While sFile <> ""
'Set variable equal to opened workbook
Set wb = Workbooks.Open(Filename:=sPath & sFile)
'Ensure Workbook has opened before moving on to next line of code
DoEvents
'Print Sheets
Set wks1 = wb.Sheets(sSHEET1_NAME)
Set wks2 = wb.Sheets(sSHEET2_NAME)
wks1.Activate
'Comment out Application.Dialogs(xlDialogPrint).Show and uncomment wks1.PrintOut if you don't want to preview prints and your default printer is correct.
Application.Dialogs(xlDialogPrint).Show
'wks1.PrintOut
wks2.Activate
'Comment out Application.Dialogs(xlDialogPrint).Show and uncomment wks1.PrintOut if you don't want to preview prints and your default printer is correct.
Application.Dialogs(xlDialogPrint).Show
'wks2.PrintOut
wb.Close SaveChanges:=False
'Ensure Workbook has closed before moving on to next line of code
DoEvents
'Get next file name
sFile = Dir
Loop
CleanUp:
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub