Consulting

Results 1 to 7 of 7

Thread: Replace all text shapes with a variable

  1. #1

    Question Replace all text shapes with a variable

    Hello! I know this question may seem a bit silly, but I'm starting in the world of VBA and I don't know many things, I saw that this forum was active and that's why I ask here :)


    I'm doing something similar to a Game Show, where on slide 1 they ask for the name of the contestants and I wanted the Shapes of all the slides to show the given name.


    I saw that many people said that I could do a For cycle and go through all the slides changing the Shapes texts one by one, but it's not efficient when you have more than 100 questions ;-;


    Is there any way to make the text of all Shapes always be the value of a real-time variable? Something like "Dim name As String", "TextRangeOfAllShapes = name" (i wish it was this easy lol).

    Thank you everyone!!!!

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    339
    Location
    Google: "powerpoint vba loop through slides"

    Review https://stackoverflow.com/questions/...label-color-to
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,095
    Location
    Without seeing your slides no-one could tell if this would work but if the names were on the Master (or custom layouts) you would only have to change it in one place. A loop would actually be quite efficient BTW and would change 100 slides in no time at all.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,721
    Location
    If you can attach a 4-5 slide presentation that show what you want to do , it's be easier to suggest things
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Quote Originally Posted by John Wilson View Post
    Without seeing your slides no-one could tell if this would work but if the names were on the Master (or custom layouts) you would only have to change it in one place. A loop would actually be quite efficient BTW and would change 100 slides in no time at all.
    Never heard of Custom Layouts! Is there anywhere I can read everything about that?

  6. #6
    Quote Originally Posted by Paul_Hossler View Post
    If you can attach a 4-5 slide presentation that show what you want to do , it's be easier to suggest things
    Sorry! I made this very simple prototype of the interactive game I'm trying to do. I hope this helps!!!

    TriviaQuestions_Prototype (1).pptx

  7. #7
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    339
    Location
    Google: "PowerPoint custom layout"
    Review https://support.microsoft.com/en-us/...5-6209be3c7b48

    Controls on first slide are ActiveX textboxes that have properties like Name and Text which can easily be referenced in VBA. The other slides have shapes with textframe but these objects do not show properties in properties sheet. I just went through a learning exercise in Word trying to address shape textframe to set text and could not get it to work - had to use ActiveX textbox.

    So, I added ActiveX textboxes to other slides. Code is like:

    Behind slide 1, replicate Change event for each textbox.
    Private Sub TextBox1_Change()
    SetNames ActivePresentation.Slides(1).Shapes("TextBox1").OLEFormat.Object.Text, 1
    End Sub
    
    Sub SetNames(strN As String, intT As Integer)
    Dim s As Integer
    For s = 2 To 6
        ActivePresentation.Slides(s).Shapes("TextBox" & intT).OLEFormat.Object.Text = strN
    Next
    End Sub
    Or this version of SetNames:
    Sub SetNames(strN As String, intT As Integer)
    Dim s As Object, sl As Slide
    Set s = ActivePresentation.Slides
    For Each sl In s
        sl.Shapes("TextBox" & intT).OLEFormat.Object.Text = strN
    Next
    End Sub
    Code to add points with each question response is next step. I have no idea how to do that. As of now, I don't even know how your answer clicks work. How does the "click to continue" work?

    This would be so much easier in Access or even vb.net.
    Last edited by June7; 04-21-2024 at 11:35 AM.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Posting Permissions

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