Consulting

Results 1 to 3 of 3

Thread: Can someone tell me why this VBA isn't working in PPT?

  1. #1

    Can someone tell me why this VBA isn't working in PPT?

    Would very much appreciate some advice here. I am trying to embed an ROI calculator within a PPT so that when a presenter is giving the presentation, they can enter values along the way and have it spit out an ROI calculation at the end.

    I am just testing a basic L * W = A formula now in order to learn the basics. It works when everything is on one slide. However, when I move the calculate button and the text box containing the answer to the second slide, and then change the code so that it references the values in the text boxes in Slide 1, it doesn't work.

    So...

    In slide 1, I have two text boxes that I created from the control toolbox. They are:

    TextBox1
    TextBox2

    In slide 2, I have one text box for the answer, and a calculate button, labeled:

    TextBox3
    Calculate

    My VBA, which is written for slide 2, looks like this:

    Private Sub Calculate_Click()

    Dim L As Single
    Dim W As Single
    Dim A As Single

    L = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text
    W = ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange.Text


    A = L * W

    TextBox3.Text = A

    End Sub

    It doesn't work, and I have tried multiple things. Anyone have any ideas? When I debug, it doesn't like the line beginning with L=, so I assume it can't reference the object in the first slide.

    One of the things I did try is to replace the (1) and (2) next to Shapes to (TextBox1) and (TextBox2), as well as ("TextBox1") and ("TextBox2"). Don't really know what I am doing here, so I was trying anything I could.

    Thanks,
    Mike

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Michael

    This is cross posted which means people will be spending time answering when there is already an answer here
    http://www.theofficeexperts.com/foru...ead.php?t=9878
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Thanks John! Sorry about that. Being a newbie on all three boards, I just sort of reached out broadband.

Posting Permissions

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