How can I get an Accurate Document count of all opened word

S

sympatico

Hi

This is what I have done. I created a form and put on button on it and
added a reference to Word Object library.

Private Sub Command1_Click()
MsgBox (Word.Application.Documents.Count)
End Sub

When I execute it, I open up several documents and I then click the button
it gives me the accurate count. When I close all those word documents and
open up 1 document. My code errors out.

Runtime error '462'

Remote server or machine is unavailable.

It's as if once I first open up word, my program will reference it, but if I
close that instance of word and open a new one, the program can no longer
reference it, I use the createObject("Word.application") but that gives me
a new instance of the word application object instead of working with the
one that already exists.

Can some one help please? Thanks
 
H

Howard Kaikow

When you close Word, you are breaking the reference to the instance of Word
you are using.

From what app are you running the code?
 

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