LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Real problems automating a mail merge

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problems using Excel as a mail merge database in Office XP djcten Excel Worksheet Functions 3 December 28th 06 05:26 PM
Code launches Mail Merge but disables the Mail Merge austris Excel Discussion (Misc queries) 0 October 14th 06 01:11 AM
mail merge excludes my headers and critical data in Word merge Nix Excel Discussion (Misc queries) 0 April 21st 06 08:35 PM
mail merge problems Bill Setting up and Configuration of Excel 0 September 23rd 05 05:07 PM
MAIL MERGE PROBLEMS FNORD Excel Discussion (Misc queries) 3 February 12th 05 01:06 AM


All times are GMT +1. The time now is 06:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"