VB 6.0 with Word 2003 mail merge

P

Paul Varner

I have a project that has been using MS Word 9.0 Object Library (Word 2000). Letters are set up in Word and a list created thru the VB program and used to print these letters. This has work fine.
The Problem comes when I updated to Word(Office) 2003. I have updated the program to reference the new MS WOrd 11.0 Object Library. When I try and run I get the following error
Run Time Error '5852
Requested object not available
The debug send me to this statement : wdApp.ActiveDocument.MailMerge.Destination = wdSendToNewDocumen

The program is set up as follows
Dim WithEvents wdApp As Word.Applicatio
Dim WithEvents wdDoc As Word.Documen
Set wdApp = New Word.Applicatio

Set wdDoc = wdApp.Documents.Open(Doc_To_Print, , ReadOnly
wdApp.ActiveDocument.MailMerge.Destination = wdSendToNewDocumen
wdApp.ActiveDocument.MailMerge.Execut

wdDoc.Close wdDoNotSaveChange

Set wdDoc = Nothin

*****
I did have Office 2000 Developer loaded. I do not have Office 2003 Developer

Can anyone point me in the right direction.

Thanks
 
D

Doug Robbins - Word MVP

I am not sure that wdDoc will be the ActiveDocument.

Either put in a wdApp.wdDoc.Activate

or use

With wdApp.wdDoc.Mailmerge
.Destination = etc
.Execute
End With

--
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
Paul Varner said:
I have a project that has been using MS Word 9.0 Object Library (Word
2000). Letters are set up in Word and a list created thru the VB program and
used to print these letters. This has work fine.
The Problem comes when I updated to Word(Office) 2003. I have updated the
program to reference the new MS WOrd 11.0 Object Library. When I try and run
I get the following error:
Run Time Error '5852'
Requested object not available.
The debug send me to this statement :
wdApp.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
 
P

Peter Hewett

Hi Paul Varner

You declaring variables using the WithEvents keyword inside a procedure (unless you've
abstracted the code from the top of the module). Obviously this wont do anything inside a
procedure.

Anyway use the document object you create and not the application object. So the code
should be like this:

Private Sub Test()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document

Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open(Doc_To_Print, , ReadOnly)

With wdDoc.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With

wdDoc.Close wdDoNotSaveChanges
Set wdDoc = Nothing
End Sub

HTH + Cheers - Peter
 

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