View Full Version : Variable in Powerpoint
Andyman448
11-17-2008, 01:30 AM
Hi, again.
I'm working on a Powerpoint presentation. And i want a variable to print your name on a page, instead of in a MSG box.
This is my current code:
Sub Button()
userName = InputBox(Prompt:="Skriv ditt namn h?r")
ActivePresentation.SlideShowWindow _
.View.GotoSlide Int(Rnd * _
ActivePresentation.Slides.Count) + 1
MsgBox ("Hi, " & userName)
End Sub
I want the userName to be printed on the second powerpoint page, on the first page I have a button that hyperlinks to the Button Sub. I can get it printed in a MSG box but it looks poor, it would be much nicer if it could print it directly on to the page.
Some help would be appreciated. Thanks :dunno
Andy Pope
11-17-2008, 02:07 AM
Some thing like this. You will need to change the shape index to suit your presentation.
Sub Button()
Dim Username As String
Username = InputBox(Prompt:="Skriv ditt namn h?r")
ActivePresentation.Slides(2).Shapes(3).TextFrame.TextRange.Text = Username
DoEvents
ActivePresentation.SlideShowWindow _
.View.GotoSlide Int(Rnd * _
ActivePresentation.Slides.Count) + 1
End Sub
Andyman448
11-17-2008, 02:18 AM
Some thing like this. You will need to change the shape index to suit your presentation.
Sub Button()
Dim Username As String
Username = InputBox(Prompt:="Skriv ditt namn h?r")
ActivePresentation.Slides(2).Shapes(3).TextFrame.TextRange.Text = Username
DoEvents
ActivePresentation.SlideShowWindow _
.View.GotoSlide Int(Rnd * _
ActivePresentation.Slides.Count) + 1
End Sub
Thank you, but I have to put a command in the power point page witch will be replaced with the variable. So what command do I have to write on the Power Point page?
Andy Pope
11-17-2008, 02:33 AM
Not sure I understand.
You said you wanted the name displayed on the second slide rather than a message box.
The code does that by placing the text in a shape. You need to know which shape the code should change. In my test I simply added a new slide and then a rectangle to the slide, this is why I used the index 3 to reference the shape.
So when run you still enter your username via the input box and the text is then written to the shape.
John Wilson
11-17-2008, 05:36 AM
Do you mean that you need the message on the Random slide not slide 2?
Try this:
Sub Button()
Dim username As String
Dim i As Integer
username = InputBox(Prompt:="Skriv ditt namn h?r")
ActivePresentation.SlideShowWindow _
.View.GotoSlide (Int(Rnd * ActivePresentation.Slides.Count) + 1)
With ActivePresentation.SlideShowWindow.View.Slide
'remove any old messages
For i = .Shapes.Count To 1 Step -1
If .Shapes(i).Tags("Added") = "yes" Then .Shapes(i).Delete
Next i
'add message
With .Shapes.AddTextbox(msoTextOrientationHorizontal, 20, 20, 200, 20)
.TextFrame.TextRange = "Hi, " & username
.Tags.Add "Added", "yes"
End With
End With
End Sub
Andyman448
11-17-2008, 09:24 AM
Not sure I understand.
You said you wanted the name displayed on the second slide rather than a message box.
The code does that by placing the text in a shape. You need to know which shape the code should change. In my test I simply added a new slide and then a rectangle to the slide, this is why I used the index 3 to reference the shape.
So when run you still enter your username via the input box and the text is then written to the shape.
Thank you it worked great!
Many Thanks!:beerchug:
braddenn
11-25-2008, 01:51 PM
This is code I am currently using to fill in text box shapes on a slide. Replace InputArray(2) with your user name. What you want is the TextFrame part. I am also setting up a hyperlink on each button to jump to that slide show.
' fill in the next button on the next slide
With ActivePresentation.Slides(2).Shapes(ShapeCount)
' .ActionSettings(ppMouseClick).Action = ppActionHyperlink
'.ActionSettings(ppMouseClick).Hyperlink.Address = _
' InputArray(0) & "\" & InputArray(1) & ".ppsm"
.ActionSettings(ppMouseClick).Action = ppActionRunMacro
.ActionSettings(ppMouseClick).Run = "Switch" & ShapeCount
.TextFrame.TextRange.Text = InputArray(2)
End With
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.