Hi. I'm a teacher. At school, I have 3 workbooks in the same folder. “Students.xls” and “Classrooms.xls” are connected to “Main.xls”.
Here is the PRINT macro.
I’m not good at macros. I need your help.
Thanks in advance.
- “Main.xls” does all the job. It has some macros and 7 worksheets. (We use it to organize the exams.)
- “Students.xls” has 30 worksheets.
- “Classrooms.xls” has 60 worksheets.
- “Numbers1” and “Numbers2” sheets in the “Main.xls”
- The used worksheets in the “Students.xls” and “Classrooms.xls” (the PRINT macro is coded for printing the coloured sheets only.)
Here is the PRINT macro.
Code:
Sub PrintTheLists()
'It prints the used lists and numbers.
Dim i As Integer, j As Integer, k As Integer
If Worksheets("Numbers1").Cells(3, 2).Value = "" Or Worksheets("Numbers2").Cells(3, 2).Value = "" Then
MsgBox "Please prepare the lists first"
Else
'ThisWorkbook.Activate
Worksheets("Numbers1").PrintOut
Worksheets("Numbers2").PrintOut
Workbooks.Open ThisWorkbook.Path & "\" & "Students.xls"
For i = 1 To 30
If Workbooks("Students.xls").Worksheets(i).Tab.ColorIndex = 4 Then
k = k + 1
End If
Next i
With Workbooks("Students.xls").Worksheets
.PrintOut From:=1, To:=k
End With
Workbooks("Students.xls").Close
Workbooks.Open ThisWorkbook.Path & "\" & "Classrooms.xls"
For i = 1 To 60
If Workbooks("Classrooms.xls").Worksheets(i).Tab.ColorIndex = 3 Then
k = k + 1
End If
Next i
With Workbooks("Classrooms.xls").Worksheets
.PrintOut From:=1, To:=k
End With
Workbooks("Classrooms.xls").Close
End If
End Sub
Thanks in advance.