简体   繁体   中英

How to change a Textbox on the current powerpoint slide with a button using vba?

I´m new to vba and need some help. I´m trying to create a module for a powerpoint presentation I´m working on. In the Presentation some of my slides contain two Textboxes displaying points for two different teams as well as two buttons to give points to either one of the teams. The module is supposed to change the textbox´s text upon pressing the corresponding button to display the new score of the team. After the points are given, the presentation proceeds until the next slide with buttons and textboxes, where he current score should be displayed.

I have several problems with the code at the moment, but I would help two know, how I can refer to a Textbox on a specific slide. I know, that " name = ActivePresentation.SlideShowWindow.View.Slide.Name " yields a String like " name = "Slide11 " if slide 11 is the current slide and I also know that " Slide11.TextBoxTeam1.Text = "Hello World " " sets the Text in the Team´s Textbox to "Hello world". But " name.TextBoxTeam1.Text = "Hello World" " doesn´t work. I´m sure it´s just about the syntax but i can´t seem to figure it out.

thanks in advance for the help.

If I'm reading your code right, name is a string variable with a value that equals the name of Slide11. You can't access Slide11's properties through a String Data Type whether the string's value is the name of the slide or not. If Slide11.TextBoxTeam1.Text = "Hello World" works and you want to replace Slide11 with a variable referencing that slide, then you need a Slide Object Variable.

Dim name As String
name = ActivePresentation.SlideShowWindow.View.Slide.name

Dim mySlide As Slide
Set mySlide = ActivePresentation.Slides(name)

mySlide.Shapes("TextBoxTeam1").TextFrame.TextRange.Text = "Hello World"

Note that mySlide.TextBoxTeam1.Text = "Hello World" was not working for me, while this was: mySlide.Shapes("TextBoxTeam1").TextFrame.TextRange.Text = "Hello World" so I replaced that line in the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM