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.