Positioning cursor in PowerPoint Add-In

Add-in Express™ Support Service
That's what is more important than anything else

Positioning cursor in PowerPoint Add-In
Positioning cursor in PowerPoint Add-In 
Leon H H




Posts: 43
Joined: 2010-04-06
I developed PowerPoint Add-In with Add-In Express. This add-in adds tracking the text changes in the slides, [similar] just like MS Word has ability to track text changes. The problem is that when I add or remove or replace the text in the TextRange the cursor gets position at the end of the TexRange instead of the end of the change (whether it new word, or place where word was deleted/replaced). I researched from A to Z why is it happening and cannot find the reason. It could be because I am doing something in other parts of my code but it could be not...
My question is how to do position the cusror right after the word I insert into the TextRange?
For example:
I do insertion like this:
PowerPoint.TextRange tr = MyTextRange.InsertAfter("insertedText");
At this point I do not know what moves the cursor to the end of the Text Box...
Is there anyway that I can control the cursor and place it right after "insertedText"?

Leon
San Diego, CA, USA
Posted 19 Jun, 2022 20:00:22 Top
Andrei Smolin


Add-in Express team


Posts: 18827
Joined: 2006-05-11
Hello Leon,

It looks like you don't receive my emails: I sent you the text below twice. Make sure the emails do not land to the Junk Email folder.

You need to call tr.Select after you insert ?Â?Ð?èZZZ?Â?Ð?é. Below is a raw-code VBA example that selects the inserted text:

Sub dfsdgf()

Dim shp As PowerPoint.Shape
Set shp = Application.ActiveWindow.Selection.ShapeRange(1)
If shp.HasTextFrame Then
    Dim tr As PowerPoint.TextRange
    Set tr = shp.TextFrame.TextRange
    Debug.Print tr.Text ' prints '111 222'
    Dim tr2 As PowerPoint.TextRange
    Set tr2 = tr.Characters(1, 3)
    Debug.Print tr2.Text ' prints '111'
    Dim tr3 As PowerPoint.TextRange
    Set tr3 = tr2.InsertAfter("!!!")
    Debug.Print tr3.Text ' prints '!!!'
    tr3.Select ' selects '!!!'
End If
'Stop
End Sub


Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Jun, 2022 02:35:12 Top
Leon H H




Posts: 43
Joined: 2010-04-06
I tried your suggestion, which is something I tried before and the result is that it shows selection from that point and to the end as shown below, and no cursor shows anywhere. (I insert "aaa")

[img]https://1drv.ms/u/s!Ahry95p8rUIZ7DL0gDxqatrJ9pT3?e=mPzrIT[/img]
Posted 22 Jun, 2022 22:46:58 Top
Andrei Smolin


Add-in Express team


Posts: 18827
Joined: 2006-05-11
Hello Leon,

I see. Here's another version of the VBA macro. Here a text range is constructed; the text range contains zero characters and starts right after the inserted text. To test this macro, paste it in the VBA project of a PowerPoint presentation, and add it to the Quick Access Toolbar.

Public Sub dfsdgf()
 
Dim shp As PowerPoint.Shape
Set shp = Application.ActiveWindow.Selection.ShapeRange(1)
If shp.HasTextFrame Then
    Dim tr As PowerPoint.TextRange
    Set tr = shp.TextFrame.TextRange
    Debug.Print tr.Text ' prints '111 222'
    Dim tr2 As PowerPoint.TextRange
    Set tr2 = tr.Characters(1, 3)
    Debug.Print tr2.Text ' prints '111'
    Dim tr3 As PowerPoint.TextRange
    Set tr3 = tr2.InsertAfter("!!!")
    Debug.Print tr3.Text ' prints '!!!'
    'tr3.Select ' selects '!!!'
    Dim tr4 As PowerPoint.TextRange
    Set tr4 = tr3.Characters(tr3.Length + 1, 0)
    tr4.Select
End If
'Stop
End Sub


Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Jun, 2022 03:04:39 Top