• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

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?

  • 2
1 Solution
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.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now