Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Lucy in the sky Lucy in the sky is offline
external usenet poster
 
Posts: 1
Default Word.Application.Documents.Count always = 0 ?

Specs: MS Word 2003 Professional under MS XP Professional.

Hi,
I'm building an VB application, which, one of its features, is the ability
to alert user when he is closing the VB application, in case there are any MS
Word documents are currently open.

Here's the code segment I wrote to obtain the number of open documents:
Dim blnExisted As Boolean
Dim objWord As Object

On Error Resume Next
Set objWord = GetObject(, "Word.Application") == LINE_1
blnExisted = (Err.Number = 0)
On Error GoTo 0

If blnExisted And Not objWord Is Nothing Then
If objWord.Documents.Count 0 Then == LINE_2
' Do something.....
End If
End If

My test steps:
STEP_1. Randomly opened one MS word document, Document1.
STEP_2. Execute the above code. Break at LINE_2.
- Found out that [objWord.Documents.Count] returned [0] instead of [1] as I
expected.

I noticed that there are two instances of WINWORD.EXE in Windows Task
Manager - Processes tab. The first instance is automatically started when the
OS is started. The second instance started when I opened Document1. The
object objWord I obtained at LINE_1 is actually the first instance, therefore
its Documents.Count is zero. So with this auto-started instance, I'm not able
to get the correct document count.

If I manually close the auto-started instance of WINWORD.EXE before
peforming STEP_1 and STEP_2, Documents.Count returns the correct value.

Could anyone please advise how can I get document count correctly, with an
auto-started WINWORD.EXE instance running?


  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Cindy M. Cindy M. is offline
external usenet poster
 
Posts: 2,416
Default Word.Application.Documents.Count always = 0 ?

Hi ?B?THVjeSBpbiB0aGUgc2t5?=,

The first thing you have to determine is: what is starting this "hidden"
instance of Word? This isn't "out-of-the-box" behavior. And since Word is
designed to pick up any running instance when you (for instance) open a
document, there would appear to be something wrong with this "orphaned instance"
of winword.exe. Perhaps an application that's using and not releasing all the
pointers correctly? Something to do with Outlook?

You need to track this down...

Specs: MS Word 2003 Professional under MS XP Professional.

Hi,
I'm building an VB application, which, one of its features, is the ability
to alert user when he is closing the VB application, in case there are any MS
Word documents are currently open.

Here's the code segment I wrote to obtain the number of open documents:
Dim blnExisted As Boolean
Dim objWord As Object

On Error Resume Next
Set objWord = GetObject(, "Word.Application") == LINE_1
blnExisted = (Err.Number = 0)
On Error GoTo 0

If blnExisted And Not objWord Is Nothing Then
If objWord.Documents.Count 0 Then == LINE_2
' Do something.....
End If
End If

My test steps:
STEP_1. Randomly opened one MS word document, Document1.
STEP_2. Execute the above code. Break at LINE_2.
- Found out that [objWord.Documents.Count] returned [0] instead of [1] as I
expected.

I noticed that there are two instances of WINWORD.EXE in Windows Task
Manager - Processes tab. The first instance is automatically started when the
OS is started. The second instance started when I opened Document1. The
object objWord I obtained at LINE_1 is actually the first instance, therefore
its Documents.Count is zero. So with this auto-started instance, I'm not able
to get the correct document count.

If I manually close the auto-started instance of WINWORD.EXE before
peforming STEP_1 and STEP_2, Documents.Count returns the correct value.

Could anyone please advise how can I get document count correctly, with an
auto-started WINWORD.EXE instance running?


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :-)

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:19 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"