Page 1 of 1

Get text from status bar

Posted: 28 Oct 2015, 07:21
by johnhill
Hi,

Would like to learn to use command StatusBarGetText and import to excel. However it doesnt seem to work. I could be missing something big here. Tried other software but result is the same.

Code: Select all

StatusBarGetText, test1, 1, 1b.xlsb - Excel
Msgbox %test1%
Is this the correct way or is the other way?

Thank you.

Re: Get text from status bar

Posted: 28 Oct 2015, 10:02
by dmatch
StatusBarGetText "Retrieves the text from a standard status bar control." Excel 2003 does not use a "standard" status bar control. AU3_Spy.exe shows statusbar text as blank instead of "Ready" which indicates it is not a standard control.

dmatch

Re: Get text from status bar

Posted: 28 Oct 2015, 23:53
by JJohnston2
What are you actually trying to read out of Excel? Perhaps it could be done in a different manner, possibly using a COM object.

Re: Get text from status bar

Posted: 22 Apr 2017, 11:03
by jeeswg
I wrote a function that gets the text from Excel 2007's status bar.

Please confirm if it works on other versions of Excel. Or use AccViewer to work out and share modified versions of the function that work on other versions of Excel.

Code: Select all

;e.g.
;WinGet, hWnd, ID, ahk_class XLMAIN
;MsgBox, % JEE_ExcelStatusBarGetText(hWnd)
;return

;e.g. status bar text: Ready/Edit/Enter
;tested on Excel 2007
;requires Acc library
JEE_ExcelStatusBarGetText(hWnd)
{
	ControlGet, hCtl, Hwnd,, NetUIHWND1, % "ahk_id " hWnd
	oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " hCtl)
	vText := oAcc.accValue(0)
	oAcc := ""
	return vText
}
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

Re: Get text from status bar

Posted: 22 Apr 2017, 12:36
by dmatch
Doesn't seem to work on EXCEL 2003. Returns NULL for hCtl. Apparently NETUIHWND1 is undefined in EXCEL2003, needs to be defined or I'm missing something else. Don't see where NETUIHWND1 is defined in either Acc.ahk or AccViewer.ahk.

Code: Select all

;e.g.
WinGet, hWnd, ID, ahk_class XLMAIN
msgbox, %hWnd% ;Gets reasonable hWnd and ahk_Class is XLMAIN so this is OK.

MsgBox, % JEE_ExcelStatusBarGetText(hWnd)
;return

;e.g. status bar text: Ready/Edit/Enter
;tested on Excel 2007
;requires Acc library
#Include C:\Program Files\Autohotkey\acc.ahk

JEE_ExcelStatusBarGetText(hWnd)
{
;ControlGet, OutputVar, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
	ControlGet, hCtl, Hwnd,, NetUIHWND1, % "ahk_id " hWnd
msgbox, hCtl=%hCtl% ErrorLevel=%ErrorLevel% ;returns hCtl NULL and ErrorLevel=1
	oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " hCtl)
	vText := oAcc.accValue(0)
	oAcc := ""
	return vText
}

Re: Get text from status bar

Posted: 22 Apr 2017, 13:07
by jeeswg
Try AutoHotkey's Window Spy to identify the control name for the status bar, and try focusing the status bar with AccViewer, to find the information needed in order to modify the Acc_Get line.

It doesn't surprise me if the control name is different, for example, DirectUIHWND controls in Explorer folder windows, weren't in Windows XP, but were in Windows 7 (and probably Windows Vista).

The numbers where it says 'Path' and the numbers in the treeview hierarchy, might provide some clues.

Best of luck.

Re: Get text from status bar

Posted: 22 Apr 2017, 13:14
by dmatch
The control name is EXCEL41 according to AccViewer. However, when I changed that the vText returned is still NULL. So there might be something else different (besides EXCEL41) needed in the Acc_Get command.hCtl is same as reported by AccViewer so that isn't the problem.

Code: Select all

	ControlGet, hCtl, Hwnd,, EXCEL41, % "ahk_id " hWnd
msgbox, hCtl=%hCtl% ErrorLevel=%ErrorLevel% ;returns same hCtl as AccViewer and ErrorLevel 0
	oAcc := Acc_Get("Object", "4.1", 0, "ahk_id " hCtl)
	vText := oAcc.accValue(0)
	oAcc := ""
msgbox, vText=%vText% ;returns NULL

Re: Get text from status bar

Posted: 22 Apr 2017, 13:17
by jeeswg
Probably you need to change "4.1" to something else, at which point the function will probably work.

Re: Get text from status bar

Posted: 22 Apr 2017, 13:18
by dmatch
Path is 4 for if that helps.

Re: Get text from status bar

Posted: 22 Apr 2017, 13:20
by dmatch

Code: Select all

oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
Still no workey.

also

Code: Select all

oAcc := Acc_Get("Object", "4.0", 0, "ahk_id " hCtl)
no workey.

Re: Get text from status bar

Posted: 22 Apr 2017, 13:23
by jeeswg
I can't be sure that it will work, however if you ever see the status bar text, in the AccViewer window e.g. in the Name or Value field, that would suggest it is possible to retrieve the text.

[EDIT:] I believe AccViewer uses 1-based indexes, so the numbers are either 1 or greater.

Re: Get text from status bar

Posted: 22 Apr 2017, 13:26
by dmatch
jeeswg wrote:I can't be sure that it will work, however if you ever see the status bar text, in the AccViewer window e.g. in the Name or Value field, that would suggest it is possible to retrieve the text.
Therein lies the possible SNAFU. Both name and value are blank in AccViewer for Path 4 Client (Status bar EXCEL41).

Re: Get text from status bar

Posted: 22 Apr 2017, 13:28
by jeeswg
Btw it may be that there is a subelement of 4 Client, from which the text can be retrieved. Otherwise, when I had Excel 2003, I used to use ImageSearch to check for Ready/Edit/Enter.

Re: Get text from status bar

Posted: 22 Apr 2017, 13:32
by dmatch
No subelement for Path 4 Client.

BTW, only testing for you since you said
Please confirm if it works on other versions of Excel.
Don't really have need right now.

Re: Get text from status bar

Posted: 22 Apr 2017, 13:53
by jeeswg
Hahaha, cheers though.

Yeah if there's a programmatic way to get that status bar text, I would like to know, even though I don't use Excel 2003 any more, just because ... you should never let yourself be defeated by the software.

==================================================

2 simple functions relating to highlighting, tested on Excel 2007. I generally do everything via macros, but the 3 functions on this page are the few exceptions.

Code: Select all

;==================================================

;e.g.
;WinGet, hWnd, ID, ahk_class XLMAIN
;JEE_ExcelFillColor(hWnd)
;return

;tested on Excel 2007
;requires Acc library
;click the Fill Color button
JEE_ExcelFillColor(hWnd)
{
	ControlGet, hCtl, Hwnd,, NetUIHWND2, % "ahk_id " hWnd
	oAcc := Acc_Get("Object", "4.14.1.1.2.11.1", 0, "ahk_id " hCtl)
	oAcc.accDoDefaultAction(0)
	oAcc := ""
}

;==================================================

;e.g.
;WinGet, hWnd, ID, ahk_class XLMAIN
;JEE_ExcelFillColorSet(hWnd, "FF0000,FFFF00,")
;return

;tested on Excel 2007
;choose the highlight colour from the Colors dialog or click Fill None
;JEE_ExcelRecentColorsAdd
JEE_ExcelFillColorSet(hWnd, vList)
{
	StrReplace(vList, ",", "", vCount), vCount += 1
	Loop, Parse, vList, % ","
	{
		if (A_LoopField = "")
		{
			SendInput !hhn ;No Fill
			continue
		}
		SendInput !hhm ;Colors dialog
		Loop, 3
			vCol%A_Index% := "0x" SubStr(A_LoopField, (A_Index*2)-1, 2)
		WinWaitActive, Colors ahk_class bosa_sdm_XL9
		WinGet, hWnd, ID, Colors ahk_class bosa_sdm_XL9
		Sleep 1000
		SendInput ^{Tab}
		ControlSetText, RichEdit20W10, % vCol1+0, % "ahk_id " hWnd
		ControlSetText, RichEdit20W11, % vCol2+0, % "ahk_id " hWnd
		ControlSetText, RichEdit20W12, % vCol3+0, % "ahk_id " hWnd
		SendInput {Enter}
		WinWaitNotActive, % "ahk_id " hWnd
		if (A_Index = vCount)
			Sleep 1000
	}
}

;==================================================

Re: Get text from status bar

Posted: 22 Apr 2017, 13:59
by dmatch
:offtopic: Ut Oh! Hijack in progress. ;)