ComObjActive with several open Word files Topic is solved
ComObjActive with several open Word files
I know if there're several open Word files, ComObjActive will connects the first open Word file, I wonder if it is possible in that case open a dialogue let the user to choose which file ComObjActive to connect.
Re: ComObjActive with several open Word files
The top right corner of this page contains a search form. A simple forum search reveals answers for you.
https://www.autohotkey.com/board/topic/145269-using-comobjactiveexcelapplication-with-multiple-instances-of-excel-2010-open/
viewtopic.php?style=1&t=104360
https://www.autohotkey.com/search/?q=comobjactive+multiple+instances
https://www.autohotkey.com/board/topic/145269-using-comobjactiveexcelapplication-with-multiple-instances-of-excel-2010-open/
viewtopic.php?style=1&t=104360
https://www.autohotkey.com/search/?q=comobjactive+multiple+instances
- flyingDman
- Posts: 2848
- Joined: 29 Sep 2013, 19:01
Re: ComObjActive with several open Word files Topic is solved
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.
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 )
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:"
}
Excel does not have this quirky behavior:
For a v2 version of GetActiveObjects see here: viewtopic.php?t=80074#p529688 (thank you @Spitzi )
14.3 & 1.3.7
Re: ComObjActive with several open Word files
Thanks, I did searched the forum before I asking this question, but I got the keyword wrong.mikeyww wrote: ↑06 Apr 2024, 06:44The top right corner of this page contains a search form. A simple forum search reveals answers for you.
https://www.autohotkey.com/board/topic/145269-using-comobjactiveexcelapplication-with-multiple-instances-of-excel-2010-open/
viewtopic.php?style=1&t=104360
https://www.autohotkey.com/search/?q=comobjactive+multiple+instances
Re: ComObjActive with several open Word files
Wow, that's amazing , your help is much appreciated.flyingDman wrote: ↑06 Apr 2024, 12:45ComObjActive 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.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).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:" }
Excel does not have this quirky behavior:
For a v2 version of GetActiveObjects see here: viewtopic.php?t=80074#p529688 (thank you @Spitzi )
Who is online
Users browsing this forum: TAC109 and 58 guests