if statement for VB Powerpoint

  • Thread starter Thread starter Tyron
  • Start date Start date
T

Tyron

What I would like to do is if a logo is already there I want a message
box to come up wich says so, some type of "if" statement

Sub KaupthingLogo()
'
' Macro recorded 06/06/2005 by tsoanes
'
With Presentations.Open("G:\Tyronne Soanes\Testingb.ppt", msoFalse)
.Slides(71).Shapes.Range(Array("KaupthingLogo")).Copy
.Close
End With
'Probably would go here'
ActivePresentation.SlideMaster.Shapes.Paste
ActiveWindow.ViewType = ppViewSlideMaster
ActivePresentation.SlideMaster.Shapes("KaupthingBankLogo").Select
ActiveWindow.Selection.ShapeRange.Delete
ActiveWindow.ViewType = ppViewNormal
With Presentations.Open("G:\Tyronne Soanes\Testingb.ppt", msoFalse)
.Slides(71).Shapes.Range(Array("KaupthingLogo")).Copy
.Close
End With
ActivePresentation.TitleMaster.Shapes.Paste
ActiveWindow.ViewType = ppViewTitleMaster
ActivePresentation.TitleMaster.Shapes("KaupthingBankLogo").Select
ActiveWindow.Selection.ShapeRange.Delete
ActiveWindow.ViewType = ppViewNormal
With Presentations.Open("G:\Tyronne Soanes\Testingb.ppt", msoFalse)
.Slides(72).Shapes.Range(Array("KaupthingTitleLogo")).Copy
.Close
End With
ActivePresentation.Slides(1).Shapes.Paste

ActivePresentation.Slides(1).Shapes.Range(Array("KaupthingBankTitleLogo")).Delete
End Sub
 
How will you distinguish the logo from another shape? Unless the logo is
linked to a file and not inserted into the PowerPoint presentation (in
which case you can use the file name), you need a way to tell if the logo
is really the logo.
--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.loyola.edu/education/PowerfulPowerPoint/
 
I have named the logo, and it would be in the presentation already, so
if it saw the named logo there it would come up with a message
 
There's probably a better way to do this, and this code assumes one slide
master, but here's something that will work:

Sub IsLogoThere()
Dim theShape As Shape

On Error GoTo NotThere
Set theShape = ActivePresentation.SlideMaster.Shapes("KaupthingLogo")
MsgBox "It's there."
Exit Sub
NotThere:
MsgBox "It's not there."
End Sub



--
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.loyola.edu/education/PowerfulPowerPoint/
 
What I would like to do is if a logo is already there I want a message
box to come up wich says so, some type of "if" statement

Dim oSh as Shape

' You'd need to change this to point to the correct slide or master, but ...
Set oSh = ActivePresentation.Slides(1).Shapes("NameOfYourShape")
If oSh Is Nothing Then
Msgbox "No shape"
Else
Msgbox "Yes, I found it"
End If
 
Steve,

Did you try this code snippet? Something similar to this was my first
thought, but it broke down if there wasn't a shape with the right name.
That's why I went the On Error route.

--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.loyola.edu/education/PowerfulPowerPoint/
 
As a followup, I tried your code snippet, and I got the same error (no
shape with that name). I guess my On Error trick is the way to go (short
of looping through all the shapes on the slide or master and testing to
see if any of them have the correct name.
--David
 
David M. said:
Steve,

Did you try this code snippet? Something similar to this was my first
thought, but it broke down if there wasn't a shape with the right name.

Right, but Tyron said he'd named the shape.
 
Right, but Tyron said he'd named the shape.

One of us is missing something, and I'm not sure which one. I thought he
was trying to first detect if the shape was there because, although he
named it, he didn't put it in every presentation. Therefore, this code
would be running as an attempt to find out if the shape was there or not.
If it is there, it's named, if it's not there, well, it's not there. I
guess Tyron will have to tell us which one of us is confused.

--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.loyola.edu/education/PowerfulPowerPoint/
 
David M. said:
One of us is missing something, and I'm not sure which one. I thought he
was trying to first detect if the shape was there because, although he
named it, he didn't put it in every presentation. Therefore, this code
would be running as an attempt to find out if the shape was there or not.
If it is there, it's named, if it's not there, well, it's not there. I
guess Tyron will have to tell us which one of us is confused.

Well, in any case, it's always best to add some error checking to production
code. I'm always reluctant to put too much of that for fear of obscuring the
main "here's how to do what you want" point.

Over to you, Tyron.
 
Back
Top