VBA/Excel/Access/Word/Outlook/MailMerge

Материал из VB Эксперт
Перейти к: навигация, поиск

Connecting Word with Access and MailMerge

 
Sub MailmergeLetter()
   Dim myLetter As Document
   Documents.Open FileName:="C:\Letter.doc"
   Set myLetter = Documents("Letter.doc")
   myLetter.MailMerge.OpenDataSource Name:="C:\store.mdb", Connection:="TABLE Employees"
End Sub



Merge to a new document and use only records 1 to 3

 
Sub MailmergeLetter()
   Dim myLetter As Document
   Documents.Open FileName:="C:\Letter.doc"
   Set myLetter = Documents("Letter.doc")
   myLetter.MailMerge.OpenDataSource Name:="C:\mydb.mdb", Connection:="TABLE Employees"
         With myLetter.MailMerge
              .Destination = wdSendToNewDocument
            With .DataSource
              .FirstRecord = 1
              .LastRecord = 3
             End With
             .Execute
         End With
End Sub