Excel get selected text - not selected cell

Add-in Express™ Support Service
That's what is more important than anything else

Excel get selected text - not selected cell
How do I get whatever text is selected in c# 
Mike Grove




Posts: 1
Joined: 2015-08-03
Suppose a cell has '12345 & 67890' as text, if a user selects just 12345, how do I get that text only? From either the cell or the formula bar if they select it there instead of in the cell. I have searched high and low and worked through a bunch of attempts using several objects and cannot find a way to get just the selected text. Any ideas would be most appreciated. I can maybe cobble up a solution that includes copying to the clipboard by doing a sendkeys, but that is a work-around at best. Either this is a most elusive beast or I have been staring at it for too long.
Posted 03 Aug, 2015 16:12:51 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Mike,

The Excel object model doesn't provide a way to achieve this.

This should be possible to do using WinAPI. You can use Spy++ to find the position in the hierarchy and properties of the window that Excel creates for editing the cell. Then you use this info to find the window programmatically. As to getting the selected text, check this page: http://www.c-sharpcorner.com/Forums/Thread/46203/read-selected-text-from-current-active-window.aspx.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Aug, 2015 08:50:49 Top