Selection withn a excel cell

Hi Experts,

when the user selects/avtivates a cell, switch to user input (F2) and than select a text. Is it possible to acces this selection via VB?
How can i do this?

Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
You can't do much eelse at the same time in Excel while the cell is in 'edit' mode, but if it is simply Selection, this will work.

Needs a reference to Microsoft Excel library.

Sub ExcelSelection()
    Dim xlApp As Excel.Application
    Dim xlWbk As Excel.Workbook
    Dim xlWks As Excel.Worksheet
    Dim strText As String
    Dim rng As Range
    Set xlApp = GetObject(, "Excel.Application")
    strText = xlApp.Selection
End Sub
Let me reword that first sentence - typos only become visible after the comment has been submitted ;)

You can't do much else at the same time in Excel while the cell is in 'edit' mode, but if it is simply selected, this will work. Otherwise the code will wait until editing is complete.
chip3dAuthor Commented:
 I already had access to the content of a cell, when only the cell is selected.

 But my problem is: how can I access the selected text, when user is editing the values of a cell. I need to gather information about the selected text or the selection  position and length, eg in form of a TextRange object of the selection.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.