Need help with VBA in PPT to do simple math

M

MichaelB1969

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
 
M

MG.Karo

try to use :
TextBox1.Value
insted of TextBox1.Text cuz u need to set focus on it before start using it

hope this will help u

Mg.Karo
 
M

MichaelB1969

MG,

Thanks for the reply! I actually did try the value statement (among many
other things), but that didn't work either. Yesterday I did receive some
code that worked. It was:

L = Slide1.TextBox1 * Slide1.TextBox2

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top