Well don't really have time to debug it, but the var is not being filled with any names. It is 0 in my testing so far so it errors out on that line.
It could be erroring for other reasons as well, just don't have time right now to look at it further.
Code:
Break On
Dim $ADoc
$ADoc = HookActiveDoc()
'ERROR: ' + @ERROR + ' - ' + @SERROR ?
'ADOC: ' + $ADoc ?
Function HookActiveDoc()
Dim $Result
Dim $objBrowserObject, $objWinShell, $objWindows
Dim $varCount, $varHwnd
Dim $objDoc
$objBrowserObject = ""
$objWindows = ""
$objWinShell = ""
$objDoc = ""
;Start: Initialize.
;'for testing purposes, assign varHwnd to an existing browser handle
$varHwnd = 197378
$objWinShell = CreateObject("Shell.Application")
$objWindows = $objWinShell.Windows
'Create objWindows: ' + @ERROR ?
For $varCount = 0 To $objWindows.Count - 1
'COUNTING WINDOWS: ' + @ERROR ?
'VAR COUNT IS: ' + $varCount ?
If $objWindows($varCount).Hwnd = $varHwnd
$objBrowserObject = $objWindows($varCount)
EndIf
Next
;End: Initialize.
If $objBrowserObject = ""
;objBrowserObject is nothing
$HookActiveDoc = ""
EndIf
$objDoc = $objBrowserObject.Document
If $objDoc = ""
;'objDoc is nothing
$HookActiveDoc = ""
EndIf
$HookActiveDoc = $objDoc
EndFunction