Mailmerge, open Data Source through macro



  • 1. Copying and pasting in a macro
    I have tried to create a macro to print to file. I typed the file name, then recorded the macro to cut the name and write to file, pasting the text I had cut as the file name. The problem was that the macro did not remember the instructions to cut and paste. Can I get round this by editing the macro VBA to insert instructions to cut and paste, and if so can anyone tell me what the VBA code would be? Thanks Dudley
  • 2. Word object and its Enumerations
    I need to store various printer settings into the database (this would be done by the user thru aintain Printersscreen). 1. In what format Ie to store the printer information (paper source, papersize ? 2. Then how do I apply the stored values to word object. (Itl accept only its enumerations)?
  • 3. find text and then copy all the paragraph before the text to a new file
    I want a macro that finds a specified text to a brunch of word documents , and then copy talla the paragraphs (one or more) before this text to another word file. I have made the macro up to the point of opening all the docs from a specified directory. But i can't make it to the end. Please if anyone knows. The macro for open all the files one by one is: Sub Macro1() Dim strFile As String, strPath As String Dim intCounter As Integer Application.ScreenUpdating = False strPath = "c:\dir1\" strFile = Dir(strPath & "*.doc") Do While strFile <> "" ff = ff + 1 ' ''Workbooks.Open strPath & strFile On Error Resume Next Documents.Open strPath & strFile, ConfirmConversions:=False, _ ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _ PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _ WritePasswordTemplate:="", Format:=wdOpenFormatAuto .................................. ................................. strFile = Dir() Loop End Sub
  • 4. Can I Hide a Macro
    I do not want users to change my macro. Can it be compiled or hidden so users cannot change or access it? Thanks F

Mailmerge, open Data Source through macro

Postby TGFzc2U » Tue, 16 Sep 2008 16:30:01 GMT


We have two templates, one containing a list of clients and one with a 
standard letter. The one with the list of clients is the source for the 
other, so we can easily create a letter to a long list of clients.

I would like to create a AutoNew macro in the template with the standard 
letter that opens the "Select Data Source" for mailmerge when opened, but 
can't figure out how?


Re: Mailmerge, open Data Source through macro

Postby Doug Robbins - Word MVP » Tue, 16 Sep 2008 19:50:21 GMT


Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Similar Threads:

1.Mailmerge data source in an Access database will not open

I am creating directory in Word 2003 by mailmerge using as the data source a 
query in an Access database (prepared in Access 2003 but in 2000 format) . 
When I attempt to browse to the data source I find that every table and query 
is listed except the one I want.

Approaching the problem via Tools > Office Links etc in Access, the required 
query is listed but draws the response " Can not open data source".

The only exceptional feature of the query i can see is that it contains a 
number of calculated fields.

2."Word was unable to open the Excel data source" Mailmerge


I am trying to perform word mail merge operation via ASP.Net using Excel as 
data source. 

Code is attached below:
 Dim wrdApp As Word.Application
        Dim wrdDoc As Word._Document
        Dim wrdMailMerge As Word.MailMerge
        Dim fileWORDName, fileEXCELName As Object

            wrdApp = New Word.Application

            fileWORDName = "ThankYou-Shalini.doc"

            wrdDoc = wrdApp.Documents.Open(FileName:=fileWORDName, 
ConfirmConversions:=False, ReadOnly _
            :=False, AddToRecentFiles:=False, PasswordDocument:="", 
PasswordTemplate _
            :="", Revert:=False, WritePasswordDocument:="", 
WritePasswordTemplate:="" _
            , Format:=Word.WdOpenFormat.wdOpenFormatAuto)

            wrdMailMerge = wrdDoc.MailMerge
            wrdMailMerge.MainDocumentType = 

            wrdApp.Visible = True
            wrdDoc.ActiveWindow.Visible = True

            fileEXCELName = "FullfillmentReport1.xls"

            wrdMailMerge.OpenDataSource(Name:= _
                fileEXCELName, _
                ConfirmConversions:=False, ReadOnly:=False, 
LinkToSource:=True, _
                AddToRecentFiles:=False, PasswordDocument:="", 
PasswordTemplate:="", _
                WritePasswordDocument:="", WritePasswordTemplate:="", 
Revert:=False, _
                Format:=Word.WdOpenFormat.wdOpenFormatAuto, Connection:= _
Files;DBQ=fileEXCELName;DriverId=790;MaxBufferSize=2048;PageTimeout=5;" _
                , SQLStatement:="SELECT * FROM 'Data'", SQLStatement1:="")

            ' Perform mail merge.
            wrdMailMerge.Destination = 
            wrdMailMerge.MainDocumentType = 

            wrdMailMerge.SuppressBlankLines = True

            wrdMailMerge.DataSource.FirstRecord = 
            wrdMailMerge.DataSource.LastRecord = 


            ' Close the original form document.
            wrdDoc.Saved = True

        Catch ex As Exception
            Dim AllWORDProcess() As System.Diagnostics.Process = 
            Dim WordProcess As New System.Diagnostics.Process
            For Each WordProcess In AllWORDProcess

            Dim AllEXCELProcess() As System.Diagnostics.Process = 
            Dim ExcelProcess As New System.Diagnostics.Process
            For Each ExcelProcess In AllEXCELProcess
            ' Release References.
            wrdMailMerge = Nothing
            wrdDoc = Nothing
            wrdApp = Nothing
        End Try

Please do the needful

3.MailMerge cannot open Access QUERY data source

I have a Word 2000 mail merge document that works fine when connecting to an
Access 2000 QUERY as its data source.  However, when I try to open the (same
or even a new) document with Word 2003 and use an Access QUERY as its data
source, Word 2003 says it cannot open the data source.  I have tried both
Access 2000 and Access 2003, but it seems to complain that there are either
no records or too few fields.  Word 2003 does seem to be able to open an
Access TABLE as a data source, but not a QUERY.

Is there a different method that I can use to sucessfully use an Access
QUERY as a MailMerge data source?  Thanks.

Chuck Hartman

4.Data source for mailmerge not selecting all data - PLEASE hel


I have the same trouble when connecting to the data source using DDE - that 
is, it doesn't appear to contain all of my information in excel and does not 
include some rows. Is there something else that I am doing wrong?

Kind regards,

"Doug Robbins - Word MVP" wrote:

> Try connecting to the data source using DDE.
> -- 
> Hope this helps.
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
> Doug Robbins - Word MVP
> "Katie" < XXXX@XXXXX.COM > wrote in message 
> news: XXXX@XXXXX.COM ...
> > Hi all,
> >
> > I am wondering if someone could please help - I am lost/baffled as to what 
> > I
> > may be doing wrong. I'm doing a mail merge using an excel table as my data
> > source. When I choose OLE DB Database Files, all of my data is selected, I
> > can filter accordingly and complete the mail merge. However, there are 
> > many
> > cells in my worksheet which contain more than 256 characters, so these 
> > come
> > across as incomplete. If I change the data source to be Excel Files via 
> > ODBC
> > (*.xls,xlsx, xlsm,xlsb), then I get the full text from my excel file, 
> > however
> > it appears to not include some rows and not show the information. As I 
> > really
> > need all of the characters, I really need to choose the data source as 
> > ODBC,
> > but I have no idea why it is not including some information from my excel
> > file.
> >
> > Could someone please help me out? I have been through the help files and
> > can't find anything. 

5.Word 2002 - Mailmerge templates changing data source via VB

I have hundreds of Mail Merge templates which use a text file in a given 
I want to open each template in vb and save it as a non mailmerge document

This should me to relocate the merge documents to a new directory.

Looking at other posts something like
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument is needed.

However I get the 2 Dialog boxes 
"xxx is a mail merge main document.  Word cannot find its data source"

"Remove Data Header or Remove All Merge Information " works fine but I want 
an automatic process

These pop up soon after opening the document and before AutoOpen
which I have created in my
Sub AutoOpen()
' AutoOpen Macro
' Macro created 07/05/2006 by JCHAPMAN
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
MsgBox "Auto open" & vbCr
End Sub

There is a thread for Peter Jamieson  	 2/04/2006  but as it was only one 
document the change was made manually.

Any suggests will be gratefully received.

6. Word basic mailmerge, changing data source file name from .doc to .txt

7. Preventing mailmerge "select data source" dialog

8. VBA Word 2002 mailmerge doc does not have data source attached

Return to MS WORD


Who is online

Users browsing this forum: No registered users and 77 guest