Consulting

Results 1 to 3 of 3

Thread: adding a variable to a text box

  1. #1

    adding a variable to a text box

    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

  2. #2
    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.

    [VBA]
    ActivePresentation.Slides(n).Shapes(n).TextFrame.TextRange.Text = n
    [/VBA]


    Hope this helps.
    Scott
    You don't understand anything until you learn it more than one way. ~Marvin Minsky

    I never teach my pupils; I only attempt to provide the conditions in which they can learn. - Albert Einstein

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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
    [vba]
    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[/vba]

    Give the shape an action of run macro

    The code should work independantly of slide or shape number
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •