Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / January 2004

Tip: Looking for answers? Try searching our database.

How to change path to mailmerge excel data source?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Reiner - 19 Jan 2004 09:12 GMT
Hi all,

I have a word mailmerge document that is linked to an excel data
source. Everytime the excel data is updated, a VBA macro starts the
mailmerge process to create the output document. My problem now is
that different users have to use this from different locations so the
even though the relative path between the excel sheet and the word
document is the same, the absolute path differs because  of different
localizations and drive names. I am now looking for a way how to make
this location-independent. I tried the OpenDataSource method from the
macro but then I get asked to select which sheet to use. Are there
other ways that work with DDE? I can not create ODBC datasources on
each system. It should work with at least Word XP / Word 2002 if
possible also Word 2000.

Best regards,
Reiner Buehl.
Cindy M  -WordMVP- - 19 Jan 2004 19:03 GMT
Hi Reiner,

In order to get Word 2002 (and later) to use DDE you need to set the
SubType argument in the OpenDataSource method. For some inexplicable
reason, this argument is not documented in either the Word 2002 or Word
2003 help (!), but if you have Intellisense turned on you should see it
in the list of arguments. This should work:

SubType:=wdMergeSubTypeWord2000

(It looks like you're German-speaking, maybe even in Switzerland? In
that case, if you can get hold of a copy of "Microsoft Word. Das
Profibuch" from MS Press you'll find a full discussion and code samples
for automating mail merge.)

> I have a word mailmerge document that is linked to an excel data
> source. Everytime the excel data is updated, a VBA macro starts the
[quoted text clipped - 8 lines]
> each system. It should work with at least Word XP / Word 2002 if
> possible also Word 2000.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
Reiner - 20 Jan 2004 13:48 GMT
Hi Cindy,

thanks for your reply. I tried using the SubType argument but when I
try to open the data source with the following code:

ActiveDocument.MailMerge.OpenDataSource
Name:="C:\Temp\conditions.xls", _
                                     
SubType:=wdMergeSubTypeWord2000

I get the following error: 0x80020005: "Type mismatch" in
METHOD/PROPERTYGET "OpenDataSource" argument "SubType".
Do you have an idea what could have gone wrong?

Best regards,
Reiner Buehl.

P.S.: Thanks for the litrature recommendation. I am german speaking
and will try to get a copy of the book asap.
Cindy M  -WordMVP- - 20 Jan 2004 18:03 GMT
Hi Reiner,

I just did a quick test and it works fine, here. Note,
however, that it may not be enough to have only the Name
and Subtype arguments. You should record a macro to see
what might be missing. Here's what I got (modified to use
the wdMergeSubTypeWord2000 enum), note the "Connection"
argument:

   ActiveDocument.MailMerge.OpenDataSource Name:= _
       "C:\Documents and Settings\xxx\My
Documents\SalesData.xls", _
       ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
       AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
       WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
       Format:=wdOpenFormatAuto, Connection:="Entire
Spreadsheet", SQLStatement _
       :="", SQLStatement1:="",
SubType:=wdMergeSubTypeWord2000

Note that I am assuming you're doing this in Word and not
another programming environment. And if the latter, that
you do have a reference set to the Word object library. I
do find the error message "Type mismatch" rather odd...

> tried using the SubType argument but when I
> try to open the data source with the following code:
[quoted text clipped - 7 lines]
> METHOD/PROPERTYGET "OpenDataSource" argument "SubType".
> Do you have an idea what could have gone wrong?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)
Reiner - 21 Jan 2004 12:35 GMT
Hi Cindy,

last night I did a lot of testing and came up with a version that
works: In another article in this group somebody posted that in
addition to Name and Connection at least SQLStatement is needed. After
changing my code to:

ActiveDocument.MailMerge.OpenDataSource
Name:="C:\Temp\Conditions.xls", _
       Connection:="Sheet1$", _
       SQLStatement:="SELECT * FROM `Sheet1$`"

everything works! From your other posts I do think that I now use
another method to connect to Excel, not DDE anymore since I do not use
the SubType parameter. Is this correct and do you have an idea if this
could still work with Word 2000?

Thanks for your help and patience!

Best regards,
Reiner Buehl.
Cindy M  -WordMVP- - 21 Jan 2004 20:17 GMT
Hi Reiner,

> last night I did a lot of testing and came up with a version that
> works: In another article in this group somebody posted that in
[quoted text clipped - 10 lines]
> the SubType parameter. Is this correct and do you have an idea if this
> could still work with Word 2000?

ah, yes, in that case you've got an OLE DB connection. Looking at the
code you post, I'm *guessing* it could work in Office 2000 to generate a
DDE connection, but you'd need to test to be sure.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.