Using slide textbox value in module

G

Guest

Hello,
I am trying to use a textbox value from a slide in a calculation. I will
have the same textbox on many slides that I will perform the same
calculation.
The module is triggered from a button on a slide master.

The textbox is named "PointValue".
I can tell the module which slide I just came from, but when I try to grab
the value of "pointValue" I get errors.

Any help would be appreciated.

Public Sub GetPoints()

Dim strPoints As String
Dim strSlidenum As String

strSlidenum = SlideShowWindows(1).View.Slide.SlideNumber

strPoints =
ActivePresentation.Slides(strSlidenum).Shapes("PointValue").TextFrame.TextRange.Text

MsgBox "slide number: " & strSlidenum & " Point Value: " & strPoints
End Sub
 
D

David M. Marcovitz

Use SlideIndex instead of SlideNumber.

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
G

Guest

I tried that, I still get the same error. (2 is the slide index)

Item 2 not found in the Slides collection
 
D

David M. Marcovitz

Change the declaration of strSlidenum to Long as in:

Dim strSlidenum As Long

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
G

Guest

That changed the error message to

Textframe (unknown member) : Invalid request. This type of shape cannot have
a textrange
 
D

David M. Marcovitz

Now, we have reached a problem that is not a code problem (except that
you could add a bunch of lines of error-checking code to produce your own
error messages). When I run that code with a shape that I have named
"PointValue" and that shape has text associated with it, it works just
fine.I wonder if you have named the wrong thing "PointValue." For
example, a line cannot have a text range, so if you named a line
"PointValue," your code would produce that error.
--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
G

Guest

It is a Textbox that I changed the Name to PointValue from the properties pop
screen.
 
B

Brian Reilly, MVP

Greg,
Like David this would work if you were naming the text box correctly.
Try this, turn on the macro recorder and select the text box you are
talking about. It will give you the actual name it is using. I get
Text Box 4 for the one I tried. then I applied a new name via VBA, not
sure what you are doing with Properties unless you are on a userform.

ActiveWindow.Selection.SlideRange.Shapes("Text Box 4").Name = "My
shape" works for me to rename the Shape.

Brian Reilly, MVP
 
D

David M. Marcovitz

Aha! It is not a regular text box. It is a control text box. You can't do
what you are trying to do in the way you are trying to do it. If all your
shapes were regular text boxes, and you had used a macro to name them
(such as the one in Example 8.7 on my site), the code would work
perfectly.

I don't know if you can access a control text box on the current slide.
You probably can, but I don't work with controls too much. The problem is
that the normal way is to use the slide number in the code as in:

Slide2.PointValue.Text

to get the text of the shape named PointValue on slide 2. In this method
of accessing the shape, the 2 cannot be determined by a variable.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
D

David M. Marcovitz

I think my response just got eaten so I'll try again.

You are using a control textbox, not a regular autoshape textbox. If you
were using a regular autoshape textbox and had named the shape using VBA
(such as with Example 8.7 on my site), then the code would work
perfectly.

I'm not sure if you can access a control on the current slide. There
probably is a way, but I don't work with controls too much. The normal
way to access a control is with the slide number hardcoded as in:

Slide2.PointValue.Text

The 2 is fixed in the code.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
D

David M. Marcovitz

My guess is that he used Properties because he has a control textbox, not
a normal textbox, and that changes everything.
--David
--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
S

Steve Rindsberg

Public Sub GetPoints()

Dim strPoints As String
' Slide number/index/id are all Longs, not Strings.
' As David mentions, use SlideIndex, not SlideNumber
Dim lSlideIndex as Long

lSlideIndex = SlideShowWindows(1).View.Slide.SlideIndex

strPoints =
ActivePresentation.Slides(lSlideIndex).Shapes("PointValue").TextFrame.TextRange.Text

MsgBox "slide number: " & cstr(lSlideIndex) & " Point Value: " & strPoints
End Sub
 
S

Steve Rindsberg

It is a Textbox that I changed the Name to PointValue from the properties pop
screen.

It's a text box *control* rather than a text box, then, I expect.

ActivePresentation.Slides(lSlideIndex).Shapes("PointValue").OLEFormat.Object.Tex
t = "whatever"
 

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