Selection withn a excel cell

Posted on 2006-05-03
Last Modified: 2010-05-01
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?

Question by:chip3d
    LVL 76

    Accepted 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
    LVL 76

    Expert Comment

    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.
    LVL 4

    Author Comment

     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

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now