ComObjActive does not connect to a file, it connects to the application (in this case MS Word). Having several files open in Word does not mean that there are several instances of the application running simultaneously.
Several files can be open and running under the same instance. One of the open files is the
activedocument. You can find the name of the
activedocument using
oWord.activedocument.Name. You can select the active document using
doc.activate.
The following script enumerates the open files using a loop and list them in a menu. Clicking on the menu item will make that item the
activedocument.
Code: Select all
oword := ComObjActive("Word.Application")
MyMenu := Menu()
loop oWord.documents.count
MyMenu.Add(oWord.documents.item(a_index).name, MyMenuMenuHandler)
MyMenu.Check(oWord.activedocument.Name) ; puts a ✓ next to the active document
MyMenu.show
MyMenuMenuHandler(ItemName, ItemPos, MyMenu)
{
doc := oWord.application.documents.item(ItemPos)
doc.activate
msgbox oWord.activedocument.Name, "Active Doc is:"
}
Note: the way
doc.activate works under v2 is different than under v1. In v1 you can use
oWord.documents(x).activate. For some reason that does not work in v2. Using
oWord.application.documents.item(ItemPos).activate in above script (replacing line 9 and 10) triggers error 0x800A16E6 (which I encountered several times already and I still don't have a full understanding of the issue).
For a v2 version of GetActiveObjects see here:
viewtopic.php?t=80074#p529688 (thank you
@Spitzi )