Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] bcjc18433@gmail.com is offline
external usenet poster
 
Posts: 1
Default My first Word Macro

Any one know what this won't work?
I have a .xlsm file that stores the source for my merge.
I connect to it using the "Select Recipients -- Use Existing List"
option on the "Mailings" Ribbon.
Connection works great.

But when I run the code below. I lose the connection to the .xlsm file
after getting "Run-time Error '4198': Command Failed"

ActiveDocument.MailMerge.DataSource.QueryString = "SELECT * FROM C:
\Documents and Settings\brian_summers\Favorites\Links\Account Tools\My
Space Files\Mail Merge Files\All Accounts (Excel 2007).xlsm WHERE
(rep_id = 12345)"

Thanks in advance,

Brian

  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default My first Word Macro

Word has several ways to connect to an Excel sheet. By default in Word 2007
it uses OLE DB. If you have already connected using that method then
a. I don't think you will be able to change the name of the workbook using
Querystring, if that is one of the things you are doing
b. your query probably needs to specify the sheet or names range name,
rather than the workbook pathname, e.g.

ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT * FROM [mysheetname$] WHERE (rep_id = 12345)"

sustituting your sheetname for mysheetname$

However, I can't check here. It might help if you could use the VBA editor's
immediate window to issue the following commands /before/ you try to change
anything:
print ActiveDocument.MailMerge.DataSource.Name
print ActiveDocument.MailMerge.DataSource.ConnectString
print ActiveDocument.MailMerge.DataSource.QueryString

You may also eventually have to take account of the following article:

http://support.microsoft.com/kb/825765

Peter Jamieson


wrote in message
ups.com...
Any one know what this won't work?
I have a .xlsm file that stores the source for my merge.
I connect to it using the "Select Recipients -- Use Existing List"
option on the "Mailings" Ribbon.
Connection works great.

But when I run the code below. I lose the connection to the .xlsm file
after getting "Run-time Error '4198': Command Failed"

ActiveDocument.MailMerge.DataSource.QueryString = "SELECT * FROM C:
\Documents and Settings\brian_summers\Favorites\Links\Account Tools\My
Space Files\Mail Merge Files\All Accounts (Excel 2007).xlsm WHERE
(rep_id = 12345)"

Thanks in advance,

Brian



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro cannot be found or has been disabled because of Macro settin JD2 Microsoft Word Help 5 March 15th 07 04:00 AM
Pause an executing Word Macro to enter info and then Macro continu strongwell Microsoft Word Help 1 August 11th 06 06:57 PM
macro runs from keyboard, but not from macro button-why? BobW Microsoft Word Help 7 May 10th 06 11:33 PM
Running Macro from Word vs running macro from vb.net prog Simon New Users 0 July 16th 05 10:17 AM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 12:40 PM


All times are GMT +1. The time now is 05:32 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"