Sorry, Greg, It's a little long, but hopefully you can tell what is going on.
I do document mine with plenty of notes. Basically this is what is
happening: We use a document generation program in Word that create a single
document that contains notices that we sent to customers. Each notice is 3
to 5 sections long. First I have to determine whether the notice is 3, 4, or
5 sections based on information that is unique to each section. After I
determine how many sections a notice is, it is printed. Then the macro calls
another macro that prints some forms. Then the notice is deleted. It then
goes through the same steps with the second notice (that is now the first
notice).
The problem that I am having, is the macro works -- once (i.e. I can run it
for the first notice, then run it again for the second notice and keep
clicking run until I am done. It also works if I step through it. But if I
try to add any kind of loop to it, it kind of scrambles the notices. I have
wondered if it is going too fast (is that possible?). I wondered if maybe I
need to somehow pause it between each notice?
If you need the macro that is called, I can send that too.
Thanks for any help you can give me.
Sub altNewPrintNOH()
'Print the Notice of Hearing.
'Requires the forms "hrformsrep.doc and hrformsnorep to be in the user's K:\
'Updated 9/10/07 to accomodate EF procedures.
Application.ScreenUpdating = true
Dim notice As Range
Dim printnotice As Range
Dim notice3 As Range
Dim printnotice3 As Range
Dim notice4 As Range
Dim printnotice4 As Range
Dim notice5 As Range
Dim printnotice5 As Range
Dim acknotice As Range
Dim blankpage As Range
Dim electronic As Boolean
Dim rep As Boolean
Dim expert As Boolean
Dim concurrent As Boolean
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
.Text = "Refer to:"
.Forward = True
.Wrap = wdFindStop
End With
If Selection.Find.Execute = False Then
End
End If
'this checks for occasional blank pages left behind.
Set blankpage =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(1).Range.End)
With blankpage.Find
.ClearFormatting
.Text = "Refer To:"
.Forward = True
.Wrap = wdFindStop
End With
If blankpage.Find.Execute = False Then
Set blankpage =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(1).Range.End)
blankpage.Delete
End If
Selection.HomeKey Unit:=wdStory
'*************VARIABLES***************
'Check for Electronic
Set notice5 =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(5).Range.End)
With notice5.Find
.ClearFormatting
.Text = "Electronic"
.Forward = True
.Wrap = wdFindStop
End With
'Electronic If
If notice5.Find.Execute("Electronic") = True Then
electronic = True
End If
'Check for Rep
Set notice =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(1).Range.End)
With notice.Find
.ClearFormatting
.Text = "cc:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
' Rep IF
If notice.Find.Execute("cc:") = True Then
rep = True
End If
'Check for Expert
Set notice4 =
ActiveDocument.Range(start:=ActiveDocument.Sections(4).Range.start,
End:=ActiveDocument.Sections(4).Range.End)
With notice4.Find
.ClearFormatting
.Text = "in accordance with your contract"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
'Expert if
If notice4.Find.Execute = True Then
expert = True
End If
'Check for concurrent
Set notice =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(1).Range.End)
With notice.Find
.ClearFormatting
.Text = "The hearing also concerns"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
'Concurrent If
If notice.Find.Execute("The hearing also concerns") = True Then
concurrent = True
End If
'************THIS STARTS THE PRINT PORTION OF THE MACRO********
Set notice =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(2).Range.End)
Set printnotice =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(2).Range.End - 1)
Set notice3 =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(3).Range.End)
Set printnotice3 =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(3).Range.End - 1)
Set notice4 =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(4).Range.End)
Set printnotice4 =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(4).Range.End - 1)
Set notice5 =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(5).Range.End)
Set printnotice5 =
ActiveDocument.Range(start:=ActiveDocument.Sections(1).Range.start,
End:=ActiveDocument.Sections(5).Range.End - 1)
Set acknotice =
ActiveDocument.Range(start:=ActiveDocument.Sections(3).Range.start,
End:=ActiveDocument.Sections(3).Range.End)
'******ELECTRONIC CASES**********
'Electronic Cases with rep and expert (5 sections)
If electronic = True Then
If rep = True Then
If expert = True Then
'print the notice
printnotice5.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
'print the forms
Call PrintHRFormsRep
'delete the notice
notice5.Delete
End If
End If
End If
'Electronic with rep but no Expert (4 sections)
If electronic = True Then
If rep = True Then
If expert = False Then
'Print the notice
printnotice4.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
' print the forms
Call PrintHRFormsRep
'delete the notice
notice4.Delete
End If
End If
End If
'Electronic with no rep with an expert (5 sections)
If electronic = True Then
If rep = False Then
If expert = True Then
' Just print the forms
Call PrintHRFormsNoRep
'delete the notice
notice5.Delete
End If
End If
End If
'Electronic with no rep AND NO expert (4 sections)
If electronic = True Then
If rep = False Then
If expert = False Then
'Just print the forms
Call PrintHRFormsNoRep
'Delete the notice
notice4.Delete
End If
End If
End If
'**********PAPER CASES***************
'Paper case with rep and expert (4 sections)
If electronic = False Then
If rep = True Then
If expert = True Then
'Print 1 copy for rep
printnotice4.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
'Concurrent = print 2 copies for the file
If concurrent = True Then
'delete the acknowledgement notice
With acknotice
.Select
.Delete
End With
'print the notice
printnotice4.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=2,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If
'Not concurrent = print 1 copy for the file
If concurrent = False Then
'delete the acknowledgement notice
With acknotice
.Select
.Delete
End With
'print the notice
printnotice4.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If ' CONCURRENT If
'print the forms
Call PrintHRFormsRep
'Delete the notice
notice4.Delete
End If
End If
End If
'Paper case with rep and no expert (3 sections)
If electronic = False Then
If rep = True Then
If expert = False Then
'Print 1 copy for rep
printnotice3.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
'Concurrent = print 2 copies (first delete the acknowledgement notice)
'
If concurrent = True Then
With acknotice
.Select
.Delete
End With
printnotice3.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=2,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If
'Not concurrent = print 1 copy (first delete the acknowldgement notice)
If concurrent = False Then
With acknotice
.Select
.Delete
End With
printnotice3.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If ' concurrent
'print the forms
Call PrintHRFormsRep
'Delete the notice
notice3.Delete
End If
End If
End If
'Paper case with no rep and an expert (4 sections)
If electronic = False Then
If rep = False Then
If expert = True Then
If concurrent = True Then
'Print 2 copies for the file (first delete the acknowledgment notice)
With acknotice
.Select
.Delete
End With
printnotice4.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=2,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If
'Print 1 copy for the file
If concurrent = False Then
With acknotice
.Select
.Delete
End With
printnotice4.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If
'print the forms
Call PrintHRFormsNoRep
'Delete the notice
notice4.Delete
End If
End If
End If
'Paper case with no rep and no expert (3 sections)
If electronic = False Then
If rep = False Then
If expert = False Then
If concurrent = True Then
'Print 2 copies for the file (first delete the acknowledgement notice)
With acknotice
.Select
.Delete
End With
printnotice3.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=2,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If
'Print 1 copy for the file
If concurrent = False Then
With acknotice
.Select
.Delete
End With
printnotice3.Select
ActiveDocument.PrintOut Range:=wdPrintSelection, Copies:=1,
PageType:=wdPrintAllPages, Collate:=True, Background:=False,
PrintToFile:=False
End If
'print the forms
Call PrintHRFormsNoRep
'Delete the notice
notice3.Delete
End If
End If
End If
Selection.HomeKey Unit:=wdStory
'Closes the notices document
'
' With ActiveDocument
' .Saved = True
' .Close
' End With
End Sub