简体   繁体   中英

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM