PDA

View Full Version : adding a variable to a text box



dinkybluebug
11-11-2008, 09:15 AM
Hi...

I know this is going to be a really dumb question to answer, but I am trying to learn a little visual basic, and I am getting myself tied up in all sorts of knots.

I am trying to add a shape to a slide in powerpoint.. The shape will have a large zero in it.... of which when the user clicks on this zero, it changes to 1.

then when you click on it again it moves to 2, and then 3, and so on.

I have tried to work this out myself, but can;t work it out.

any help would really be appreciated.

I have attached the powerpoint file I have been working with

Please help.....

many thanks

Marc

Demosthine
11-11-2008, 03:38 PM
Good Morning.

Welcome to the Forum. It's always good to have new members.

That being said, for your specific question, you will need to use a Macro Action. Inside the Procedure, you'll want to access the particular TextBox using:

Ensure Macros are enabled in PowerPoint.
Tools | Macros... | Security... | Medium or Low
Reopen your Presentation
Press Alt+F11 to open the Visual Basic Environment.
Right-click the Project Explorer and Insert Module.
Create a new Public Sub.
Close the Visual Basic Environment.
Insert your TextBox.
Right-click the TextBox and select Custom Action.
Set it to Run Macro.



ActivePresentation.Slides(n).Shapes(n).TextFrame.TextRange.Text = n



Hope this helps.
Scott

John Wilson
11-12-2008, 01:53 AM
It's not a dumb question!

I would always try to avoid using Slide and Shape number to reference objects (eg Slides(n),Shapes(n))

These numbers can very easily change when slides or shapes are added, deleted or moved.

Try this code in the VBE

Sub count(oshp As Shape)
Dim Ival As Integer
Ival = Val(oshp.TextFrame.TextRange)
oshp.TextFrame.TextRange = CStr(Ival + 1)
With oshp.ActionSettings(ppMouseClick)
.Action = ppActionRunMacro
.Run = "count"
End With
End Sub

Give the shape an action of run macro

The code should work independantly of slide or shape number