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

2

7

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.

Quintuplet answered 26/2, 2011 at 1:40 Comment(2)
Would you go back to the beginning and describe what you're actually trying to achieve because there may be more than one way to skin this particular (metaphorical) cat.Douzepers
I don't think there's any other way to say it. I want the current text and cursor position from the formula bar. My question was if it was possible to do that via the Excel COM API or XLL API (not via horrible hacks), which it looks like it isn't.Quintuplet
L
3

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.

Landowner answered 26/2, 2011 at 10:13 Comment(0)
D
2

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.

Douzepers answered 27/2, 2011 at 21:28 Comment(3)
No solution will work for all versions from 2003+ 2007 is very different from 2003 in many important ways.Douzepers
I did some digging into 2003 and 2007 and the pseudo edit box is very similar in both versions. Both have CS_OWNDC which could indicate that the implementer has chosen to do all the drawing directly. This is bad for you because it may just be a plain old window. I could find no evidence suggesting it is an edit box. The message logs from Spy say the same. I suspect you're dead in the water.Douzepers
Sub-classing the control won't get you anywhere either because you don't get to 'see' what is actually drawn on the DC without grabbing a copy and (stop right there, pain ensues).Douzepers

© 2022 - 2024 — McMap. All rights reserved.