R
roy.ball
I would really appreciate some input from the fine people of this group
[microsoft.public.word.vba.beginners]. The following is a description
of my situation, directly followed by my script. Yes - I recorded
macros to get the nuts and bolts of the script.
Thanks in advance!
Our application writes a data and token file to the users PC and then
invokes Word for the merge. I had a request to generate trial notices
en mass, but the user wanted them grouped by department copy. When
trial notices are generated, five copies are created, one for each
department, but they must be grouped by department. This prevents me
from doing the usual and creating a 5-page merge template, one page for
each department.
The following script first stores the default printer, and then
specifies the printer to use for this document. From here, the merge is
performed and a dynamic department name is inserted into the footer.
The template is merged, sent to the printer, and then closed. The
process then repeats itself for the remaining departments
Finally, the printer is set back to the default.
Here is the script
Sub formcopy()
'
' Copy Script
' Created 9/7/2005 by Roy Ball
'
' This VBA script selects the page footer,
' inserts the copy text, merges the CourtView
' data, prints the forms for that recipient(s)
' closes the merged data form, and resets the
' footer text.
'PrntScrpt
Dim sCurrentPrinter As String
On Error Resume Next
sCurrentPrinter = ActivePrinter
ActivePrinter = "\\cocprint01\is-hp4200-1"
' Defendant Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="DEFENDANT COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Defendant Copy
' Bondsman Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="BONDSMAN COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Bondsman Copy
' Admin Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="ADMIN COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Admin Copy
' Attorney Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="ATTORNEY COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Attorney Copy
' Clerk Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="CLERKS COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Clerk Copy
ActivePrinter = sCurrentPrinter
'!PrntScrpt
End Sub
[microsoft.public.word.vba.beginners]. The following is a description
of my situation, directly followed by my script. Yes - I recorded
macros to get the nuts and bolts of the script.
Thanks in advance!
Our application writes a data and token file to the users PC and then
invokes Word for the merge. I had a request to generate trial notices
en mass, but the user wanted them grouped by department copy. When
trial notices are generated, five copies are created, one for each
department, but they must be grouped by department. This prevents me
from doing the usual and creating a 5-page merge template, one page for
each department.
The following script first stores the default printer, and then
specifies the printer to use for this document. From here, the merge is
performed and a dynamic department name is inserted into the footer.
The template is merged, sent to the printer, and then closed. The
process then repeats itself for the remaining departments
Finally, the printer is set back to the default.
Here is the script
Sub formcopy()
'
' Copy Script
' Created 9/7/2005 by Roy Ball
'
' This VBA script selects the page footer,
' inserts the copy text, merges the CourtView
' data, prints the forms for that recipient(s)
' closes the merged data form, and resets the
' footer text.
'PrntScrpt
Dim sCurrentPrinter As String
On Error Resume Next
sCurrentPrinter = ActivePrinter
ActivePrinter = "\\cocprint01\is-hp4200-1"
' Defendant Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="DEFENDANT COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Defendant Copy
' Bondsman Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="BONDSMAN COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Bondsman Copy
' Admin Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="ADMIN COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Admin Copy
' Attorney Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="ATTORNEY COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Attorney Copy
' Clerk Copy
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
Selection.TypeText Text:="CLERKS COPY"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False,
PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0,
PrintZoomPaperHeight:=0
ActiveWindow.Close (wdDoNotSaveChanges)
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'!Clerk Copy
ActivePrinter = sCurrentPrinter
'!PrntScrpt
End Sub