Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All,
I am trying to automate a mail merge from excel to word. I have tried the following code which works in word, but doesnt work using my word object (wrd) Can anyone help. Nath Dim wrd As Word.Application Dim doc As Word.Document Set wrd = CreateObject("word.application") Set doc = wrd.Documents.Add doc.Select With wrd .Visible = True .ActiveDocument.MailMerge.MainDocumentType = wdMailingLabels .ActiveDocument.MailMerge.OpenDataSource Name:= _ "Z:\Development\Engine\ver2.2\Data_For_Mege.xl s", ConfirmConversions:= _ False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _ WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _ Connection:= _ "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";Us e r ID=Admin;Data Source=Z:\Development\Engine\ver2.2 \Data_For_Mege.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Je" _ , SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:= _ wdMergeSubTypeAccess .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""Title""" .Selection.TypeText Text:=" " .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""Forename""" .Selection.TypeText Text:=" " .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""Surname""" .Selection.TypeParagraph .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""Add_1""" .Selection.TypeParagraph .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""Add_2""" .Selection.TypeParagraph .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""Add3""" .Selection.TypeParagraph .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""Add_4""" .Selection.TypeParagraph .ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _ , Text:="""PostCode""" .WordBasic.MailMergePropagateLabel End With |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
problems using Excel as a mail merge database in Office XP | Excel Worksheet Functions | |||
Code launches Mail Merge but disables the Mail Merge | Excel Discussion (Misc queries) | |||
mail merge excludes my headers and critical data in Word merge | Excel Discussion (Misc queries) | |||
mail merge problems | Setting up and Configuration of Excel | |||
MAIL MERGE PROBLEMS | Excel Discussion (Misc queries) |