Consulting

Results 1 to 5 of 5

Thread: How to modify the text inside a text box with VBA?

  1. #1

    Exclamation How to modify the text inside a text box with VBA?

    Hello guys.

    I have a problem when I try to locate a named text box in a named slide to change the text inside the text box.
    Any of you know how to do it?

    For example this code here is not working:

    ActivePresentation.Slides("Anlass").Select
        ActiveWindow.Selection.ShapeRange("Group 88").Select
        ActiveWindow.Selection.ShapeRange.GroupItems(Index:=3).TextFrame.TextRange.Select
        ActiveWindow.Selection.ShapeRange.GroupItems(Index:=3).TextFrame.TextRange.Characters(Start:=15, Length:=10).Select
        ActiveWindow.Selection.TextRange.Font.Bold = msoTrue
        ActiveWindow.Selection.Unselect
    Thanks in advance
    Last edited by Aussiebear; 04-28-2023 at 08:55 PM. Reason: Added code tags

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    You should probably explain exactly what you are trying to do!

    Is the text really in groupitems(3)?

    Assuming it is try:

    Sub boldme()
    ActivePresentation.Slides("Anlass").Shapes("Group 88").GroupItems(3) _
    .TextFrame.TextRange.Characters(15, 10).Font.Bold = msoTrue
    End Sub
    Last edited by Aussiebear; 04-28-2023 at 08:55 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Well I've come close to what I wanted to do:

    I can increment the score of the quiz, and it is displayed in the TextBox of the current Slide.

    How can I assign this value to a textbox on the next slide?

    I've tried copying / pasting the box, but a new objectname will be assinged

    How can I keep my score and have it show on each slide?


    My code so far:


    Sub addToPersonA()
    Dim resultA As Integer
    On Error Resume Next
    resultA = ActivePresentation.Slides(1).Shapes("Text Box 5").TextFrame.TextRange.Text
    Set tb = ActivePresentation.Slides(1).Shapes("Text Box 5")
    resultA = resultA + 1
    With tb
        .TextFrame.TextRange.Text = resultA
        .Font.Size = 32
    End With
    End Sub


    Anyone still awake to save me before sunset?
    Last edited by Aussiebear; 04-28-2023 at 08:56 PM. Reason: Adjusted the code tags

  4. #4
    Updated my post above - hope it's better now ?!

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Few things then:
    Because you have Dim ResultA inside the sub it will be reset to zero each time it runs

    Place it OUTSIDE of the sub but in the same module then it will keep score

    Dim ResultA
    Sub AddtoPersonA
    etc
    If you name the textbox yourself rather than the default name it won't change when pasted
    In 2007 you can do this in the selection pane in earlier versions you must use vba :

    Sub Namer()
    'select the first box and run this
    On Error Resume Next
    ActiveWindow.Selection.ShapeRange(1).Name = "MyBox"
    End Sub
    To add text on the current slide in the show

    With ActivePresentation.SlideShowWindow.View.Slide _
        .Shapes("MyBox").TextFrame.TextRange
        .Text = ResultA
        .Font.Size = 32
    End With
    Hope that helps

    John
    Last edited by Aussiebear; 04-28-2023 at 08:57 PM. Reason: Adjusted the code tags
    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
  •