Aotoshape text box find cursor position

HarryS

Board Regular
Joined
May 2, 2008
Messages
212
How do you find ( in VBA) the setstart position in an autoshape text box. Not in a forms text box. What is needed is the equivalent of
ActiveSheet.Shapes("TexHelp") .TextFrame.Characters.SelStart
When editing this type of text box. Clicking on a position and highlighting it allows for font size color etc modifications so the system has the cursor position in the characters... but how do get this from VBA .. especially how to find the clicked word. It seems to have all sorts of funny 255 char string restrictions and no record macro code.. Were the Ms people switching from VB in this area
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
In XL 2007 , the Macro recorder doesn't generate any code when selecting some text in a shape textbox. I have looked through the Shapes Properties and Methods but nothing seems to return the selected text. Maybe in versions prior to xl 2007 the Macro recorder generates code.

If you just want to retrieve the selected text string without manipulating it then you could copy the text to the clipboard and access it from there.

Something along these lines :

Code:
Option Explicit

Private Declare Sub keybd_event Lib "user32.dll" _
(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2


Sub Test()

    Dim oDataObject As Object
    Dim sShapeSelectedText As String

    Set oDataObject = _
    GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    With oDataObject
        .Clear
        keybd_event vbKeyControl, 0, 0, 0
        keybd_event vbKeyC, 0, 0, 0
        keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0
        keybd_event vbKeyC, 0, KEYEVENTF_KEYUP, 0
        DoEvents
        .GetFromClipboard
        sShapeSelectedText = .GetText
    End With
    MsgBox "Seelected Text : '" & sShapeSelectedText & "'"
    
End Sub
 
Upvote 0
Thanks Jaafar;; This is about the 20th time that I have appreciated your extreme understanding and knowledge of api functions. What I am doing is trying to set up a help text box that takes ranges from a spread sheet WITH Formating.. Your routine works well past the mad 255 chr limit .. and will allow the user to pick a word .. so that the help in the text box can find and show all ranges in the sheet that contain that word. ( How do you recall all of those functions ).. It allows the user without programming skills to adjust the help spread sheet.. Instead of needing to understand compiled help files.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top