I'm sorry jeeswg but in trying to straighten this out, I feel more confused than ever.
I earlier referred to three of your scripts which begin as follows:
Script #1
Code: Select all
;[Excel_Get function]
;MS-Office-COM-Basics/Excel_Get.ahk at master · ahkon/MS-Office-COM-Basics · GitHub
;https://github.com/ahkon/MS-Office-COM-Basics/blob/master/Examples/Excel/Excel_Get.ahk
q:: ;excel - list workbooks (tested with Excel 2007)
WinGet, hWnd, ID, A
...
Script #2
Code: Select all
; Excel_Get by jethrow (modified)
; Forum: https://autohotkey.com/boards/viewtopic.php?f=6&t=31840
; Github: https://github.com/ahkon/MS-Office-COM-Basics/blob/master/Examples/Excel/Excel_Get.ahk
...
Script #3
Code: Select all
;[Acc functions]
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
;Basic Ahk_L COM Tutorial for Excel - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/69033-basic-ahk-l-com-tutorial-for-excel/#entry437036
q::
Loop, 2
...
and which (hopefully to simplify), I will now refer to as:
#1
;[Excel_Get function]... — contains hotkey q::
#2
;Excel_Get by jethrow (modified)...
#3
;[Acc functions]... — contains hotkey q::
You said:
jeeswg wrote:- The two scripts with q hotkeys are completely separate.
and
jeeswg wrote:- The Excel_Get function needs to be in your script
So from that, I understand that #1 & #3 do not belong together and #2 should always be included. But when I tried #1 followed by #2 in the same script, I got this error:
---------------------------
Warning: This local variable has the same name as a global variable.
Specifically: hwnd (in function Excel_Get)
Line#
058: oXl := Excel_Get("ahk_id " hWnd)
059: For oWorkbook, in oXl.Workbooks
060: vOutput .= oWorkbook.Name "
" oWorkbook.FullName "
"
061: oXl := ""
062: Clipboard := vOutput
063: MsgBox,vOutput
064: Return
---> 069: {
071: WinGetClass,WinClass,%WinTitle%
072: if !(WinClass == "XLMAIN")
073: Return,"Window class mismatch."
074: ControlGet,hwnd,hwnd,,Excel7%Excel7#%,%WinTitle%
075: if (ErrorLevel)
076: Return,"Error accessing the control hWnd."
077: VarSetCapacity(IID_IDispatch, 16)
For more details, read the documentation for #Warn.
---------------------------
and when I tried #3 followed by #2 in the same script, I got this error:
---------------------------
Error: Call to nonexistent function.
Specifically: Acc_ObjectFromWindow(hCtl, -16)
Line#
007: Return
018: ControlGetText,vText,EXCEL71,A
019: MsgBox,%vText%
020: Return
040: Loop,2
041: {
042: ControlGet,hCtl,Hwnd,,"Excel7" A_Index,ahk_class XLMAIN
---> 043: oWin := Acc_ObjectFromWindow(hCtl, -16)
044: oBook := oWin.Parent
045: MsgBox,oBook.FullName
046: oWin := oBook := ""
047: }
048: Return
053: {
054: Static,h,DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
The program will exit.
---------------------------
Also, from this:
Can be either ClassNN (the classname and instance number of the control) or the control's text
And you were using _Text again as text that the window must contain.
- If you list the controls that a window contains, you will see that the '_Text' Excel workbook, has a ClassNN such as EXCEL71 / EXCEL72 / EXCEL73.
I don't understand: "classname and instance number" or what is meant by "the controls text" or "text that the window must contain" or "list the controls that a window contains".
I did — after clicking somewhere in one of the workbooks to make it active — run this script:
Code: Select all
q::
ControlGetText, vText, EXCEL71, A ; retrieves name of control (workbook filename)
MsgBox %vText%
Return
and it simply returned the filename of that workbook.
I'm sure I've hampered my understanding by not clarifying the use of "_Text" earlier but is it possible at this point for you to post the
exact and complete script I should use so I can simply copy & paste it in order to designate the active control in an
If/
Else script?
If that's possible then I believe I can work backwards to learn/understand what the script is doing.
Thanks for your patience and assistance.
Steve