Is there a way to get the text and cursor position from the formula bar in Excel?

716 Views Asked by At

I'd like to get the current (possibly uncommitted) text out of the formula bar in Excel (from an addin in-process). All "usual" techniques don't work, like GetWindowText(...), etc.

As for cursor position: GetCaretPos actually works (returns the x,y coords of the caret), but EM_CHARFROMPOS doesn't (always returns 0) so that's a dead end.

Is this functionality exposed through COM or to the XLL API in any way?

EDIT: I'd also like to point out that I think the majority of my issues come from the fact that the formula bar is (at least I'm 99% sure) NOT an edit control, which can be seen by looking at its window class.

2

There are 2 best solutions below

0
On

The formula bar, and indeed most of the controls in Office are non-standard. Sending standard messages will not yield success.

I imagine the only option will be to reverse-engineer the executable code.

3
On

SteveN, which version of Excel ? The control will be a window. Office 2010 is 'nicer' in this respect, using more standard controls. You could use Spy to watch all the messages that get sent to that control and try mimicking those to see what you get. Long road though.