Referring to slides from within a VB macro

  • Thread starter Thread starter Neil
  • Start date Start date
N

Neil

Hi All,

I have a macro autorun when a slideshow is run that pops up a dialogue
requesting the presenters name.

Two questions regarding this:

1. How can I have this run the first time in a session that someone runs a
slideshow ?

2. The presenters name is used to fill a text box in the slideshow, on about
slide 4. How can I refer to the slide (4) in the macro ?


Thanks,

Neil
 
First off:

I would recommend setting the presentation up as a KIOSK (if you haven't
already). This will ensure the user has to use buttons you provide. On
Slide 1 have a "Start" button that opens the UserForm1 and collects the
information. On the "OK" button of the form have the information be put
into the desired variables (code sample provided below).

You need to know the name of the object on the desired slide to control what
it contains. See code below! Some variable names are assumed.

1. First step is to copy and paste the following macro into your Module.
You would select your object on Slide 4, click "Tools", "Macro", "Macros",
select the "NameShape" macro, then click "Run". PowerPoint assigned a name
to your shape. Type over the name with your name (like, "FirstName", etc.),
then press ENTER.

Sub NameShape()
Dim Name$
On Error GoTo AbortNameShape

If ActiveWindow.Selection.ShapeRange.Count = 0 Then
MsgBox "No Shapes Selected"
Exit Sub
End If
Name$ = ActiveWindow.Selection.ShapeRange(1).Name

Name$ = InputBox$("Give this shape a name", "Shape Name", Name$)

If Name$ <> "" Then
ActiveWindow.Selection.ShapeRange(1).Name = Name$
End If
Exit Sub

AbortNameShape:
MsgBox Err.Description

End Sub

2. Second step is to obtain the information they typed on the UserForm. I
will assume you already have that down pat. If not, holler back and I will
send some sample code. What I normally do is to verify some of the
information on the form, then call a macro to assign the text strings to the
desired variables in my module. This is why I normally use the "Public"
declaration instead of "Dim". With that said, one of your lines of code
behind the "OK" button will say - AssignName (which takes the data and ports
it to the desired object on the desired slide).

=====Code sample====
'Declarations
Public strLastName as String
Public strFirstName as String

' This assumes you have two variables as listed above and the two text boxes
on your UserForm are txtFirstname and txtLastName

Sub AssignName()
strFirstName = UserForm1.txtFirstName.Text
strLastName = UserForm1.txtLastName.Text

ActivePresentation.Slides(4).Shapes("FirstName").TextFrame.TextRange.Text =
strFirstName
ActivePresentation.Slides(4).Shapes("LastName").TextFrame.TextRange.Text
= strLastName
End Sub

If you only have one shape and want both strings in it, then simply
concatenate the two strings (strFirstName & strLastName)

Holler back if this doesn't make sense!
 
2) Check the PP VBA help for the 'SlideShowNextSlide Event' (w/o the
quotes).

1) Use a global variable to store the name. Then, in the
SlideShowBegin event, check if the global variable is empty. If it is,
ask for the name. If it is not, you already know the name.

This will work as long as the same presenter is responsible for
multiple presentations. Obviously, PP cannot figure out when one
presenter replaces another.

You may be better off always asking for the name at the start of a
presentation, but, if the global variable contains something use it to
fill the response box.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
Back
Top