palaeontology
Active Member
- Joined
- May 12, 2017
- Messages
- 444
- Office Version
- 2016
- Platform
- Windows
I'm currently using the following code to copy a template sheet (called PrintTemplate) multiple times and rename them with names from a list found in a given range ...
This code is working perfectly most of the time, but occasionally prints just one of the sheets multiple times and doesn't print the other sheets.
For example, if the range houses 4 different student names, the code should result in 4 copies of the template sheet being printed, each with one of the four student names, but occasionally what is produced is 4 sheets each with the same one name .. sometimes it will be the first name in the list, sometimes the second name, etc etc ... there's no consistency as to which name it gets 'hung up' on.
Following the code that produces named copies of the template sheet, I have 2 more codes .. one to cause the printing of these sheets, the other to delete the sheets just created ...
Can anyone see why my code might not produce the correct desired result each time ?
Could the print require slowing down, to give time for each newly formed sheet to be read and printed ????
Kind regards,
Chris
Code:
Dim ws As Worksheet, Ct As Long, c As RangeSet ws = Worksheets("Student Profile Template")
Application.ScreenUpdating = False
For Each c In Sheets("PrintTemplate").Range("AH49:AH100")
If c.Value <> "" Then
ws.Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value
Ct = Ct + 1
End If
Next c
Application.ScreenUpdating = True
This code is working perfectly most of the time, but occasionally prints just one of the sheets multiple times and doesn't print the other sheets.
For example, if the range houses 4 different student names, the code should result in 4 copies of the template sheet being printed, each with one of the four student names, but occasionally what is produced is 4 sheets each with the same one name .. sometimes it will be the first name in the list, sometimes the second name, etc etc ... there's no consistency as to which name it gets 'hung up' on.
Following the code that produces named copies of the template sheet, I have 2 more codes .. one to cause the printing of these sheets, the other to delete the sheets just created ...
Code:
For Each ws In ThisWorkbook.Worksheets If ws.Name Like "#####" Then
ws.Range("P22:U22").Font.Color = vbWhite
ws.Range("P22:U22").Interior.Color = vbWhite
ws.PageSetup.Orientation = xlLandscape
ws.PrintOut From:=1, To:=1
End If
Next ws
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name Like "#####" Then ws.Delete
Next ws
Can anyone see why my code might not produce the correct desired result each time ?
Could the print require slowing down, to give time for each newly formed sheet to be read and printed ????
Kind regards,
Chris
Last edited: