I know how to get the count of active documents and the active document name.
I'd like to extract the index number of the active document.
Any suggestions?

TIA

Re: Obtain the index number of the active document. by Jean-Guy

Jean-Guy
Tue Jan 11 19:06:04 CST 2005

drbobsled was telling us:
drbobsled nous racontait que :

> I know how to get the count of active documents and the active
> document name. I'd like to extract the index number of the active
> document.
> Any suggestions?
>

Try with:

Dim MyIndex As Long

MyIndex = Application.ActiveWindow.Index


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org




Re: Obtain the index number of the active document. by Jonathan

Jonathan
Tue Jan 11 19:08:38 CST 2005


"drbobsled" <drbobsled@discussions.microsoft.com> wrote in message
news:12DCC6B5-8991-45CA-86EE-5E7F13C3EB09@microsoft.com...
>I know how to get the count of active documents and the active document
>name.
> I'd like to extract the index number of the active document.
> Any suggestions?


Documents.Count returns the number of open documents

The active documnent is Document(1) by definition. The index numbers change
depending on the order in which they were activated.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Re: Obtain the index number of the active document. by Helmut

Helmut
Wed Jan 12 04:54:50 CST 2005

Hi everybody,

>The active document is Document(1) by definition.

hmm...
Could this vary with the operating system and the Word version?
Here and now
Application.ActiveWindow.Index
returns 4 e.g., as Jean-Guy said.
Or am I missing something?

>The index numbers change depending on the order in which they were activated.

hmm... again.

Here with Windows 98 and Word XP the list of open documents
is sorted in alphabetical order. Though I think I remember
that this is different with NT and Windows 2000.

Can't check it right now.

Cheers

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/








Re: Obtain the index number of the active document. by Jonathan

Jonathan
Wed Jan 12 05:15:09 CST 2005

Hi Helmut,

Further research shows we were both wrong!

First of all, there is a distinction to be made between the index number of
the active document(which is what the original question asked for) and the
index number of the active window. For instance, a document might be open in
more than one window, and each window would have a different index number.

It appears that Document(1) is by definition the most recently *opened*
document, not necessarily the Active Document. If you have multiple
documents open and switch between them, the ActiveDocument changes, but
Document(1) does not.

You can find out the current index number of the active document (as apposed
to active window. The foillowing code puts the index number into the
variable iIndex

Dim iIndex as Long
Dim i As Long
For i = 1 to Documents.Count
If Documents(i).FullName = ActiveDocument.FullName Then
iIndex = i
Exit For
End If
Next i

However, Document(1) does change when a new document is opened or created.
Therefore, grabbing the index number of the document is not a reliable way
of keeping track of it. The reliable way of keeping track of a document is
to assign an object variable to it like this

Dim oDoc As Document
Set oDoc = ActiveDocument

Subsequently, and reference to oDoc is the reference to the document that
was assigned, and this does not change when additional documents are opened
or closed. Changes can be made to the document by using oDoc in just the
same way as you would normally use ActiveDocument, without having to
activate the document and bring it to the foreground.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


"Helmut Weber" <elmkqznfwvccbf@mailinator.com> wrote in message
news:1ov9u0hehqh6n07bmflkb3rrum7t4r969q@4ax.com...
> Hi everybody,
>
>>The active document is Document(1) by definition.
>
> hmm...
> Could this vary with the operating system and the Word version?
> Here and now
> Application.ActiveWindow.Index
> returns 4 e.g., as Jean-Guy said.
> Or am I missing something?
>
>>The index numbers change depending on the order in which they were
>>activated.
>
> hmm... again.
>
> Here with Windows 98 and Word XP the list of open documents
> is sorted in alphabetical order. Though I think I remember
> that this is different with NT and Windows 2000.
>
> Can't check it right now.
>
> Cheers
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP
> "red.sys" & chr(64) & "t-online.de"
> Word XP, Win 98
> http://word.mvps.org/
>
>
>
>
>
>
>


Re: Obtain the index number of the active document. by Helmut

Helmut
Wed Jan 12 05:39:02 CST 2005

Hi Jonathan,

>Further research shows we were both wrong!

right again! ;-)

Thanks for your time.

Cheers

Helmut