Test if object exists

W

Wicked Wizard

I have a PPT2000 presentation where I have a shape that contains different
versions of text according to certain circumstances. I need to extend that
now so that I can either have text or a multimedia object in the shape.
Therefore I need to test if it has text, and if so delete it and place the
object (I can do the putting in the object bit) and also check if it has the
object, and if so, delete it and write some text, according to need.

My VBA is on a steep upward learning curve atm! Any help will be gratefully
received.
 
B

Bill Dilworth

Try

Sub test()
Dim oShp As Shape
'assign oShp...
If oShp.HasTextFrame Then
oShp.TextFrame.DeleteText
End If
End Sub



Post back if you need additional help with this.

Bill Dilworth
Microsoft PPT MVP Team
Users helping fellow users.
===============
Please spend a few minutes checking vestprog2@
out www.pptfaq.com This link will yahoo.
answer most of your questions, before com
you think to ask them.

Change org to com to defuse anti-spam,
ant-virus, anti-nuisance misdirection.
..
..
 
W

Wicked Wizard

Thanks: I'll try it later today and let you know...

Will the same method work for the multimedia object?

WW
 
W

Wicked Wizard

Right, that takes me forward a bit...

I am working with a shape on slide 6 which I need to manipulate: change the
contents as appropriate in accordance with what the user clicks. I've done
that before with just text, no problems. Now I need to be able to delete
the text and play a movie instead.

As I can't tell the state of the shape (named "textBox") when the user makes
his choice, I now have

If ActivePresentation.Slides(6).Shapes("testBox").HasTextFrame Then
ActivePresentation.Slides(6).Shapes("testBox").TextFrame.DeleteText
End If

which works fine.

Having cleared the way, I now need to place the video so that it is aligned
centre and middle of the shape "textBox". I had that fine when I was
working in design mode, but I've been toying with it and the object browser
for the last hour and I can't make it work in presentation mode at all.
Your last comment tells me why, but I am puzzled that with
expression.AddMediaObject expression returns a shapes object. Clearly I
have several sticks by the wrong end.

Of course, the video has to be sized as well. In draft mode
with ActiveWindow.Selection.ShapeRange
.scalewidth 0.6, msoFalse, msoScaleFromTopLeft
.scaleHeight 0.6 etc
worked fine. But now I can't get the darn thing on the page, let alone
scale it! And when I do I can't use Selection to find it.

I did try

dim myVideo as Object, but then I found I could not define which file it
was, let alone where to place it and how to size it.

I must be a Dumbo first class!

WW
 
W

Wicked Wizard

Many thanks. I'll be working on it today.

WW

Steve Rindsberg said:
As I mentioned, you can't add media TO a shape; media IS a shape. Adding
it
creates a new shape.


Now, as in "now that I'm in slide show view"? Yep. You can't select
anything
in slide show view, so code that depends on the selection will fail.

Try something along these lines:

' Watch for linebreaks! Edit filenames/object names as needed
Sub DueMeBeforeICodeAgain()

Dim oTextShape As Shape
Dim oMediaShape As Shape

Set oMediaShape =
ActivePresentation.Slides(5).Shapes.AddMediaObject(FileName:="file.avi",
Left:=262.5, Top:=255#)

' Get a reference to your existing text shape
Set oTextShape = ActivePresentation.Slides(5).Shapes("textThing")

oMediaShape.Top = oTextShape.Top
oMediaShape.Left = oTextShape.Left
' etc

' possibly:
' oTextShape.Delete or
' oTextShape.Visible = False

ActivePresentation.SlideShowWindow.View.GotoSlide (5)

End Sub




Quite the opposite.


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
 
W

Wicked Wizard

Thanks to you, Steve, I have some workable code.

Sub testAndDelete()

dim oTextShape as shape
dim oMediaShape as shape

'first check if there is any text in the frame and if there is delete it

If ActivePresentation.Slides(6).Shapes("testBox").HasTextFrame Then
ActivePresentation.Slides(6).Shapes("testBox").TextFrame.DeleteText
End If

'now define the variables

Set oMediaShape =
ActivePresentation.Slides(6).Shapes.AddMediaObject(FileName:="D:\word2005\saveTypingTutorial\useAutoCorrect.avi",
Left:=262.5, Top:=255#)
Set oTextShape = ActivePresentation.Slides(6).Shapes("testBox")

'now size the video shape

oMediaShape.ScaleHeight 0.56, msoTrue
oMediaShape.ScaleWidth 0.56, msoTrue

'then place it - couldn't find a way to centre the two shapes, but this
works fine

oMediaShape.Left = oTextShape.Left
oMediaShape.Top = oTextShape.Top
oMediaShape.IncrementLeft 111

End Sub

All I have to do now is adapt it a bit for the working version which will be
distributed to my colleagues on CD. The presentation is a tutorial on
automating text in Word, covering AutoCorrect, AutoText, Bookmarking text in
an external file, Document Scraps and Macros. This slide is the one on
AutoCorrect, and it'll have 3 tabs on it. The user clicks on a tab to learn
either about how to create an AutoCorrect entry, or how to use it, or to
watch a video of the process. I've used the technique before with just
text, this takes it to a stage beyond. I am beginning to think I could make
a living doing this sort of thing!

WW
 

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