I have written a macro (with help from this forum, thanks) that prompts a user for 3 files to import worksheets, then it creates custom headers and footers for those worksheets, prints them out, and deletes them. Now I need another macro for situations where the number of, and which worksheets needed, will not be known until the first worksheet is opened.
How can I modify the following code to prompt the user for the first file, modify and print, then ask the user if they need to open another file and repeat the process?
Private Sub CommandButton1_Click()
Dim wb1 As Workbook, wb2 As Workbook, wb3 As Workbook
Dim Ret1, Ret2, Ret3
Set wb1 = ActiveWorkbook
'~~> Get the first File
Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select CHAR-OP")
If Ret1 = False Then Exit Sub
'~~> Get the 2nd File
Ret2 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select CONNECTION")
If Ret2 = False Then Exit Sub
'~~> Get the 3rd File
Ret3 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select HOUSING")
If Ret3 = False Then Exit Sub
Set wb2 = Workbooks.Open(Ret1)
wb2.Sheets(1).Copy Before:=wb1.Sheets(1)
ActiveSheet.Name = "Char_OP"
wb2.Close SaveChanges:=False
Set wb2 = Workbooks.Open(Ret2)
wb2.Sheets(1).Copy After:=wb1.Sheets(1)
ActiveSheet.Name = "CONNECTION"
wb2.Close SaveChanges:=False
Set wb2 = Workbooks.Open(Ret3)
wb2.Sheets(1).Copy After:=wb1.Sheets(1)
ActiveSheet.Name = "HOUSING"
wb2.Close SaveChanges:=False
Set wb3 = Nothing
Set wb2 = Nothing
Set wb1 = Nothing
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Changing header/footer in " & ws.Name
With ws.PageSetup
.LeftHeader = " "
.CenterHeader = "&12Sales Order#: &B&U" & Sheet1.Range("$B$6") & "&B&U QTY: &B&U" & Sheet1.Range("$B$7")
.RightHeader = "&12Due Date: &B&U" & Sheet1.Range("$B$8")
.CenterFooter = "&12&UENGRAVE:&U &B" & Sheet1.Range("$B$10") & "&B DATE CODE: &B&U" & Sheet1.Range("$B$11")
.RightFooter = "&08PRINTED: &D"
End With
Next ws
Set ws = Nothing
Application.StatusBar = False
Sheets("Char_OP").PrintOut
Sheets("CONNECTION").PrintOut
Sheets("HOUSING").PrintOut
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then ws.Delete
Next ws
Application.DisplayAlerts = True
End Sub
Bookmarks