View Single Post
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Curt Curt is offline
external usenet poster
 
Posts: 32
Default Mail Merge Macro for Printing

this counter idea for a first try at mail merge. Want word to stop searching
all of excel 6000 rows. 200 are more than enough. Takes to long to do all. I
recorder the following macro thru experminting it works except for the search
problem. Any help greatly appreciated
Thanks

Sub xy()

' xy Macro
' Macro recorded April 4, 2008 by Curtiss A. Greer
'
ActiveDocument.MailMerge.EditMainDocument
Selection.TypeParagraph
Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
True, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeParagraph
ActiveDocument.MailMerge.OpenDataSource Name:="C:\Parade\Parade.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"DSN=Excel
Files;DBQ=C:\Parade\Parade.xls;DriverId=790;MaxBuf ferSize=2048;PageTimeout=5;" _
, SQLStatement:="SELECT * FROM `Data$`", SQLStatement1:=""
' ActiveDocument.MailMerge.EditMainDocument
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:= _
"Contact_Person"
Selection.TypeParagraph
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:= _
"Address"
Selection.TypeParagraph
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:= _
"CityState"
Selection.TypeParagraph
ActiveDocument.MailMerge.Fields.Add Range:=Selection.Range, Name:="Zip_"
Selection.TypeParagraph
ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT * FROM `Data$` WHERE ((`Contact Person` IS NOT NULL ) AND (`
Address` IS NOT NULL ) AND (`City&State` IS NOT NULL ) AND (`Zip ` IS NOT
NULL ) AND (`Amount` = 0))" _
& ""
With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord tried 1 here
.LastRecord = wdDefaultLastRecord tried 50 here no luck
End With
.Execute Pause:=True
End With
CommandBars("Stop Recording").Visible = False
End Sub




"Graham Mayor" wrote:

Merge to a new document then the following macro will split the merge to
print as separate files

Sub SplitMergeLetterToPrinter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to print each letter created by a
' mailmerge as a separate file.
'
Letters = ActiveDocument.Sections.Count
Counter = 1
While Counter Letters
ActiveDocument.PrintOut Background:=False, Range:=wdPrintFromTo, _
From:="s" & Format(Counter), To:="s" & Format(Counter)
Counter = Counter + 1
Wend
End Sub


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Joe Perfiry wrote:
Hi I have a Sharp MX5500 printer and I do mail merge jobs of three
pages to about 8000 customers. I want each page to use a different
tray as I have letterhead in one, continuation in another etc If I
select the printer and choose different trays it will only print the
very first job from these. The rest will go to default. I want a
macro that will enable this. Could someone tell me one please?