Consulting

Results 1 to 4 of 4

Thread: Change properties at cursor

  1. #1

    Change properties at cursor

    Hi everyone,
    I am trying to replicate what powerpoint does when you change properties of what you are typing (without selecting text), eg clicking "red" as font color:

    • When you click red, the text you type from there is red
    • Using ActiveWindow.Selection.TextRange.Font.Color.RGB = RGB(255, 0, 0) does not work, as nothing is really selected (you just have your cursor at a specific position in the text)

    I tried browsing the selection object properties but was not able to find anything.
    Would really appreciate your help!

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,999
    Location
    I don't know a sensible way but here is a clunky way ...

    Sub apply_Red()
    Dim otxr2 As TextRange2
    On Error Resume Next
    Set otxr2 = ActiveWindow.Selection.TextRange2
    If Not otxr2 Is Nothing Then
    otxr2.InsertAfter ("A")
    otxr2.Font.Fill.ForeColor.RGB = vbRed
    SendKeys "{BKSP}"
    End If
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Thank you so much John!! It is clunky but at least it works (what I have not been able to so far)! I have customized it so it changes the typed text to red when it is black and vice versa. Maybe there's sth to do it in a "cleaner" way by sort of selecting the character after where you are typing. Although don't know how if you are at the end of your textbox.
    For reference my code:
    Sub redfont()
    
    Set otxr2 = ActiveWindow.Selection.TextRange2
    Dim lettre_avt As Integer
    
    If (Not otxr2 Is Nothing) Then
        If otxr2 = "" Then
            lettre_avt = ActiveWindow.Selection.TextRange2.Start - 1
            If ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(lettre_avt).Font.Color.RGB <> 0 Then
                'type black
                otxr2.InsertAfter ("A")
                otxr2.Font.Fill.ForeColor.RGB = vbBlack
                SendKeys "{BKSP}"
            Else
                'type red
                otxr2.InsertAfter ("A")
                otxr2.Font.Fill.ForeColor.RGB = vbRed
                SendKeys "{BKSP}"
            End If
        End If
    End If
    
    End Sub

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,999
    Location
    I hate cluncky too but AFAIK there's no other way. Hopefully someone else will pop up with a better way!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •