'Get location of selected charcters inside textframe if an Excel object with VBA

Is there a programmatic way (with VBA) to get the beginning and end positions of selected text inside a TextFrame object (of a text box) on an Excel spreadsheet? Like here below for "problem". enter image description here

I was looking for something in Characters method but did not find anything.



Solution 1:[1]

I don't think you can reach into the selection in a regular textbox. If you can use an ActiveX textbox, then this is possible. You can insert an ActiveX text box from the Developer tab of the ribbon as seen here:

enter image description here

This will make a text box name textbox1 as seen here:

enter image description here

Here's a subprocedure accessing the selected text:

Sub selected_text()

    Dim tb As Object
    Set tb = ActiveSheet.TextBox1
    Debug.Print Mid(tb.Text, tb.SelStart, tb.SelLength)

End Sub

On note is that get an "enter" character in the text box, users need to use "ctrl+enter"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gove