Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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
Posted to microsoft.public.word.mailmerge.fields
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro cannot be found or has been disabled because of Macro settin | Microsoft Word Help | |||
Pause an executing Word Macro to enter info and then Macro continu | Microsoft Word Help | |||
macro runs from keyboard, but not from macro button-why? | Microsoft Word Help | |||
Running Macro from Word vs running macro from vb.net prog | New Users | |||
2000 to 2002 macro and "Could not open macro storage" | Mailmerge |