PDA

View Full Version : Displaying user assigned values



palex
09-27-2014, 08:40 PM
Hello,
A couple of very basic questions for a VBA newbie.

If there is user input, say with the following macro,

Sub Getname()
userName = InputBox(Prompt:="Enter the name you want to be addressed by:")
MsgBox ("Welcome to the presentation, " & userName)
End Sub

How can I display the value of userName in a subsequent slide?
Also, in the event of multiple macros assigning variables via user input, how can I calculate the product of these variables and display the result on a subsequent slide?

Thanks!

John Wilson
09-28-2014, 02:02 AM
Sopposing you have a shape on SLIDE 3 named nameShape

Try


Sub Getname()
Dim UserName As String ' always declare variables - you will need to for the next part
UserName = InputBox(Prompt:="Enter the name you want to be addressed by:")
MsgBox ("Welcome to the presentation, " & UserName)
With ActivePresentation.Slides(3).Shapes("nameShape").TextFrame.TextRange
.Text = "I knew you were coming " & UserName
End With
End Sub

Make sure the shape exists on slide 3 or it will error.

palex
09-28-2014, 04:00 PM
Great, thanks.
One followup - How would you clear the values that appear via the ActivePresentation? When I close the PowerPoint and reopen it, the old values still appear in the shapes.

Thanks again!

John Wilson
09-29-2014, 01:43 AM
IF you named the shape as I suggested try this:


Sub OnSlideShowTerminate(SW As SlideShowWindow)
Dim osld As Slide
On Error Resume Next
For Each osld In SW.Parent.Slides
osld.Shapes("nameShape").TextFrame.DeleteText
Next
End Sub