Consulting

Results 1 to 9 of 9

Thread: Changing text in an existing textbox

  1. #1
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location

    Changing text in an existing textbox

    Is there any way of changing either the captions of existing labels or the text in existing textboxes using vba? (I can't find out how to identify existing labels or textboxes on a slide ) Any ideas gratefully received!

  2. #2
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Every time you add a shape to a slide, PPT assigns a name to it (like "Rectangle 6"). If you want to modify a specific shape, you will have to know this name so you can reference it in your code. Otherwise, you can create the shape in VBA and name it yourself, like this:
     
    Sub test()
    'The following example adds a rectangle to myDocument, gives it the name Red Square, and then sets its foreground color and line style.
    Set myDocument = ActivePresentation.Slides(2)
        With myDocument.Shapes.AddShape(Type:=msoShapeRectangle, _
                Top:=144, Left:=144, Width:=72, Height:=72)
            .Name = "Red Square"
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
            .Line.DashStyle = msoLineDashDot
        End With
    End Sub
    Once you know the name, you can refer back to that object in vba to modify it.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  3. #3
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Sorry, more to the point of your question:
    [vba]
    Sub test2()
    'This example adds a vertical label that contains the text "Test Label" to myDocument.
    Set myDocument = ActivePresentation.Slides(2)
    myDocument.Shapes.AddLabel(Orientation:=msoTextOrientationVerticalFarEast, _
    Left:=100, Top:=100, Width:=60, Height:=150).TextFrame _
    .TextRange.Text = "Test Label"
    End Sub
    [/vba]
    This comes straight from the VBA help files.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  4. #4
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location

    Changing text in an existing textbox

    Thanks for the reply. It isn't quite what I was hoping for. I have made a template for a blockbusters game (to use with my class at school) and I wanted to randomise the letters in the hexagons each time it was used. I have been trying to reference labels or textboxes that are already present on the slide. I think I may be trying to do the impossible!!

  5. #5
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Hi again,

    Could you post the code and/or the file you're working with? Someone should be able to help you further if they see the specifics of what you're working with - and perhaps lead you in another direction you might not have thought of.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  6. #6
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location

    Changing text in an existing text box

    Thanks again - I'm attaching the file, it still very basic but I've posted a few notes with the code. I think I may have found a way around the problem, not ideal but better than nothing. I can change the text in text boxes using vba before running the slideshow (not during it) so will be able to randomise at this stage. Still can't change label captions (see module2).

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Hi

    Firstly using labels is just complicating things and making the vba more difficult. Just use normal autoshapes with text. I have attached a version of your file with a shuffle routine and the start of a select case routine to goto the correct slide. You should be able to see how to complete this (NB only A.B.C & D work at the moment)
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location

    Solved: Changing text in an existing textbox

    Many thanks. It works a treat!! Only problem now is that I don't know how to mark the thread as 'solved'!

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Glad to help. If you get stuck with making the correct shape change colour email me John AT SIGN technologytrish.co.uk. Can I also suggest that you change the answer inputted to lower case using LCase(strsanswer) this will avoid problems with capital letters.
    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
  •