Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
jm_dunning jm_dunning is offline
external usenet poster
 
Posts: 1
Default Word/Excel VBA mail merge fails with filtered results

I have a VBA macro that copies uses an Excel file to do a mail merge
in Word. Everything works properly, except if the Excel file has
filtering, in which case I get

Run-time error '5640':
Word could not re-establish a DDE connection to Microsoft Excel to
complete the current task

The code I'm using is as follows:

With wordDoc.MailMerge
.OpenDataSource Name:=strSourcePath, Connection:="Entire
Spreadsheet", SQLStatement:=strSQL, SubType:=wdMergeSubTypeWord2000 '
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With


Is there another argument I could use for "Connection:", eg., "Visible
Range"

Any tips would be appreciated.

TIA, John
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Word/Excel VBA mail merge fails with filtered results

You can try

"_FilterDatabase"

instead of

"Entire Spreadsheet"

However, you will then see blank rows where Excel has hidden the rows it
has filtered out, so you would need to change the query. How to do that
may depend on the version of Office - I'm not sure you can set
SQLStatement in the opendatasource, so you might need to leave the
SQLStatement parameter out of your opendatasource statement and put
something like the following code after the opendatasource

..DataSource.Querystring = "SELECT * FROM " & strSourcePath & "WHERE
(mycolumn is not NULL)

But, if you need further assistance...
a. do you really need to use DDE?
b. which version of Word/Excel?

Peter Jamieson

http://tips.pjmsn.me.uk

jm_dunning wrote:
I have a VBA macro that copies uses an Excel file to do a mail merge
in Word. Everything works properly, except if the Excel file has
filtering, in which case I get

Run-time error '5640':
Word could not re-establish a DDE connection to Microsoft Excel to
complete the current task

The code I'm using is as follows:

With wordDoc.MailMerge
.OpenDataSource Name:=strSourcePath, Connection:="Entire
Spreadsheet", SQLStatement:=strSQL, SubType:=wdMergeSubTypeWord2000 '
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With


Is there another argument I could use for "Connection:", eg., "Visible
Range"

Any tips would be appreciated.

TIA, John

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
Word Mail Merge not picking up filtered data from Excel Kelley Microsoft Word Help 2 June 5th 09 05:44 PM
Mail Merge with Excel shows incorrect results Jan Mailmerge 2 September 17th 08 11:58 PM
word 2003 mail merge using foxpro 9 tables as a data source fails Daniel Williams Microsoft Word Help 16 January 31st 08 05:18 PM
Why doesn't mail merge show filtered excel worksheets REVA Mailmerge 1 January 24th 06 02:30 PM
How do I do mail merge using filtered data from excel REVA Mailmerge 3 January 24th 06 02:30 PM


All times are GMT +1. The time now is 05:58 AM.

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"