Get text from status bar

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Get text from status bar

28 Oct 2015, 07:21

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.
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

28 Oct 2015, 10:02

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
JJohnston2
Posts: 204
Joined: 24 Jun 2015, 23:38

Re: Get text from status bar

28 Oct 2015, 23:53

What are you actually trying to read out of Excel? Perhaps it could be done in a different manner, possibly using a COM object.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get text from status bar

22 Apr 2017, 11:03

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
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

22 Apr 2017, 12:36

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
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get text from status bar

22 Apr 2017, 13:07

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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

22 Apr 2017, 13:14

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
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get text from status bar

22 Apr 2017, 13:17

Probably you need to change "4.1" to something else, at which point the function will probably work.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

22 Apr 2017, 13:18

Path is 4 for if that helps.
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

22 Apr 2017, 13:20

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.
Last edited by dmatch on 22 Apr 2017, 13:23, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get text from status bar

22 Apr 2017, 13:23

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.
Last edited by jeeswg on 22 Apr 2017, 14:06, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

22 Apr 2017, 13:26

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).
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get text from status bar

22 Apr 2017, 13:28

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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

22 Apr 2017, 13:32

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.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get text from status bar

22 Apr 2017, 13:53

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
	}
}

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
dmatch
Posts: 49
Joined: 02 Oct 2013, 09:56

Re: Get text from status bar

22 Apr 2017, 13:59

:offtopic: Ut Oh! Hijack in progress. ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], jaka1, OrangeCat and 155 guests