Get mail merge datasource name

Posted on 2006-07-21
Last Modified: 2010-04-30
I need to be able to open a mail merge document in VB (which I can do) but I need to be able to extract the datasource name embedded in the file.
Question by:kncoughlin
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 76

Expert Comment

ID: 17159275

but you might also need



Author Comment

ID: 17160414
I had tried that already and got an error 91...object variable or with block variable not set.  Here's my code:

Dim oWord As Word.Application
Dim oDoc As Word.Document

Set oWord = New Word.Application
oWord.Visible = True
oWord.Documents.Open (filename)
LVL 76

Expert Comment

ID: 17160555
You need to set the oDoc object.

Set oDoc = Word.Documents.Open(FileName)
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.


Author Comment

ID: 17176886
Unfortunately, it is coming up blank with the name.  I don't know if the fact that I'm using a comma delimited txt file for my datasource has anything to do with it.
LVL 76

Expert Comment

ID: 17178357
It works for me with a CSV file. It returns the full file name.

What value do you get for the Type property?

MsgBox oDoc.MailMerge.DataSource.Type

Author Comment

ID: 17178731
I'm getting a -1.  When I try to open the document thru Word (no VB intervention) I'm getting the following message:

Opening this document will run the following SQL command:


Data from your database will be placed in the document.  Do you want to continue?

I'm guessing that until this question is answered, it does not embed the datasource.  Perhaps that's why the VB is not seeing it.

Thanks in advance for all your help....I'll up the points.
LVL 76

Accepted Solution

GrahamSkan earned 500 total points
ID: 17178825
That's a security feature, but there is a registry mod for it:;EN-US;825765

Author Comment

ID: 17178884
T H A N K   Y O U !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question