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/
>
>
>
>
>
>
>