Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with this VBA for simple math in PPT? 1

Status
Not open for further replies.

MichaelB1969

Programmer
Sep 10, 2008
3
US
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. 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, I need to change the code so that it references the values in the text boxes in Slide 1, and that is what isn't working.

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.

Thanks,
Mike
 
Hi Mike,

I am on 2007 here but this works for me.

result = Slide1.TextBox1 * Slide1.TextBox2

Hope this helps.

Peter.

Remember- It's nice to be important,
but it's important to be nice :)
 
It works (I am using PPT 2003)! Yahooo! This was a huge help. Thanks so much. You don't realize how much time I wasted being stubborn and trying to figure this out on my own!

Thanks again!
Mike
 
No problems Mike.

Sometimes you can't see the wood for the trees.

Peter.

Remember- It's nice to be important,
but it's important to be nice :)
 



Mike,

Welcome to Tek-Tips. Hope you find the many forums on this site helpful.

You no doubt, have noticed the little purple stars while browsing the forum. These are submitted by other members, often the authors of the threads, when they want to...
[blue]
Thank Tek-Tip Contributor
for this valuable post!
[/blue].
You might want to consider doing this if you believe that this was appropriate for Peter's contributeon.


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I did not notice the stars. Was too busy trying to get this thing to work! Anyway, thanks for the tip. I went ahead and gave Peter's post a star.

Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top