ComobjActive not working for IE Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chase1
Posts: 18
Joined: 15 Jul 2016, 19:42

ComobjActive not working for IE

20 Sep 2017, 23:57

Hi All,

Really odd problem.
This code errors on this line:
wb := ComObjActive("InternetExplorer.Application")

However, works perfectly when I do this:
wb := ComObjActive("Excel.Application")

It also works perfectly if I do:
wb := ComObjCreate("InternetExplorer.Application")

Am I missing something?
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: ComobjActive not working for IE  Topic is solved

21 Sep 2017, 06:01

How to access an existing IE object

Code: Select all

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}

Access an IE object by Window/Tab Name:

Code: Select all

IEGet(name="") {
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame     ;// Get active window if no parameter
   Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
   for wb in ComObjCreate("Shell.Application").Windows()
      if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
         return wb
}
https://autohotkey.com/board/topic/4705 ... -tutorial/
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa and 222 guests