Peter Ritchie
asked on
Calling Word macros from Excel to add MailMerge fields
I have some specific questions relating to Excel vba, Word vba and MailMerge.
My questions are:
1. I can get this instruction to work from Word vba:
ActiveDocument.MailMerge.F ields.Add Range:=Selection.Range, Name:="FirstName"
I can access a Word document from Excel vba, however this instruction fails. So my question is can this instruction
be issued from an Excel macro?
2. From Word it is possible to format the output of a MailMerge field using Toggle Field Codes. How can this be done from a vba macro? I have managed to do it using find and replace but surely there is a better way?
3. From an Excel macro I can invoke a simple Word macro, with code like:
Set WD = CreateObject("Word.Applica tion")
WD.Run "runTxtConversion", txtFile
For me this works fine so long as there is only a single Word document open.
How can I make it work if there are multiple Word document?
I would be grateful for either direct answers or references to books or on-line documents that can answer my questions.
Many thanks,
Peter
My questions are:
1. I can get this instruction to work from Word vba:
ActiveDocument.MailMerge.F
I can access a Word document from Excel vba, however this instruction fails. So my question is can this instruction
be issued from an Excel macro?
2. From Word it is possible to format the output of a MailMerge field using Toggle Field Codes. How can this be done from a vba macro? I have managed to do it using find and replace but surely there is a better way?
3. From an Excel macro I can invoke a simple Word macro, with code like:
Set WD = CreateObject("Word.Applica
WD.Run "runTxtConversion", txtFile
For me this works fine so long as there is only a single Word document open.
How can I make it work if there are multiple Word document?
I would be grateful for either direct answers or references to books or on-line documents that can answer my questions.
Many thanks,
Peter
Peter
To use Application.Run when there are multiple documents open specify the document the sub you want to run is in.
For example
To use Application.Run when there are multiple documents open specify the document the sub you want to run is in.
For example
Application.Run "'My Document.docm'!runTxtConversion"
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
This illustrative macro uses early binding, so needs a reference (Tools/References) to the MIcrosoft Word Object library.
Open in new window