PDA

View Full Version : Replace all text shapes with a variable



Polarin00
04-19-2024, 10:43 PM
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!!!!

June7
04-20-2024, 12:18 AM
Google: "powerpoint vba loop through slides"

Review https://stackoverflow.com/questions/24929913/powerpoint-vba-loop-all-slides-all-shapes-find-chart-set-datalabel-color-to

John Wilson
04-20-2024, 06:47 AM
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.

Paul_Hossler
04-20-2024, 08:03 AM
If you can attach a 4-5 slide presentation that show what you want to do , it's be easier to suggest things

Polarin00
04-20-2024, 08:45 PM
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?

Polarin00
04-20-2024, 09:03 PM
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!!!

31538

June7
04-21-2024, 10:02 AM
Google: "PowerPoint custom layout"
Review https://support.microsoft.com/en-us/office/edit-and-re-apply-a-slide-layout-6f4338f8-555f-49cf-9835-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.