vba mail merge problem

M

Mike Molyneaux

Running 2003 on xp pro.
have latest updates on both.


receive run-time error '5852':
requested object is not available.

code runs find on office 2000 & nt4, sp6

code:

with activeDocument.MailMerge
.Destination = wdSendToNewDocument 'Error on this line'
.SuppressBlankLines = False
with .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
end with
.execute Pause:=False
end with

code created by recording macro as doing the merge
the merge worked fine as I recorded macro.

now get vb error

any help greatly appreciated

Mike
 
D

Doug Robbins - Word MVP

You get that problem if the activedocument is not a mailmerge main document
or does not have a datasource attached to it. To prevent it from happening,
use:

If ActiveDocument.MailMerge.State = wdMainAndDataSource Then
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument 'Error on this line'
.SuppressBlankLines = False
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End If


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Cindy M -WordMVP-

Hi Mike,

Doug explains what's causing the error, but not why you're
getting it...

Are you opening these documents manually, or using VBA code?
If VBA code, then you're probably running into this:

"Opening This Will Run the Following SQL Command" Message
When You Open a Word Document - 825765
http://support.microsoft.com?kbid=825765
Running 2003 on xp pro.
have latest updates on both.


receive run-time error '5852':
requested object is not available.

code runs find on office 2000 & nt4, sp6

code:

with activeDocument.MailMerge
.Destination = wdSendToNewDocument 'Error on this line'
.SuppressBlankLines = False
with .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
end with
.execute Pause:=False
end with


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 :)
 
S

snareg

We run into the same error when doing a mail merge on XP Office but not on all XP Office installations.

Our app sets the references to Word and Office in the reference listing under tools instead of in code. The original was set to 9 on both of the refrences. I took the merger document onto an XP machine running at 10 on both Word and office in the refernces. I clicked off the reference to Office 10 and saved and closed the documents. Then I opened it again and let the code run. It ran fine with no errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top