PDA

View Full Version : How to finad a shape by location?



elunicotomas
04-11-2012, 11:56 AM
Hi again,

I managed to create a a macro (thanks cosmo) that paste "flags" (shapes of different colors) to clasify the slides of a presentation.

There are 3 types of flags, each one corresponds to the current status of the slide.

Now i want that when im going to change the status of the slide (paste a new flag) replace the old flag with the new one. Beacuse now I keep pasting shapes over the previous flag and on and on... I want the macro to see if in a specific location there is a flag, if positive , delete the flag so i can paste the new one, this this make sense??

Or maybe you come up with a better solution hehe

Sub AZ_Banderita_Azul()

'if there´s no slide selected the shape will be pasted in the previous slide
On Error Resume Next
Err.Clear
'Debug.Print "The current slide is Slide " & ActiveWindow.View.Slide.SlideIndex
If Err <> 0 Then
ActiveWindow.ViewType = ppViewNotesPage
ActiveWindow.ViewType = ppViewNormal
'Debug.Print "The current slide is Slide " & ActiveWindow.View.Slide.SlideIndex
End If

'creates shape

slideLocation = ActiveWindow.View.Slide.SlideIndex

Set myDocument = ActivePresentation.Slides(slideLocation)

Dim shp As Shape

Set shp = myDocument.Shapes.AddShape(msoShapeRectangle, 570, 0, 150, 100)

With shp
.Line.Visible = msoFalse
.Fill.Transparency = 0.35
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 176, 240)
.Fill.Solid
.TextFrame.TextRange.Text = "READY TO PROOF"
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 0)
.TextFrame.TextRange.Font.Bold = msoTrue
.TextFrame.TextRange.Font.Name = "Arial"
.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignRight
.TextFrame.MarginRight = 3
.TextFrame.MarginTop = 3
.TextFrame.TextRange.Font.Size = 12
.TextFrame2.VerticalAnchor = msoAnchorTop
End With

End Sub

Cosmo
04-12-2012, 05:18 AM
I wouldn't use the location of the shape, but give it a specific name (Or, add a 'Tag' property) such as 'Flag'.

Before you add your new shape, loop through the shapes on the slide and if you find one with the proper name or tag, then delete it. And set the name/tag property when you create the new shape.

The Name property is very easy and straigtforward; Using a 'Tag' requires a little more work, but adds a few benefits - you can add multiple tags, the tags are not directly editable by the user, and the tags are a name/value pair, so you could create a Tag named 'Flag' for your shape, and the value could be the type of flag, which could help allow you to identify which flag is used.

elunicotomas
04-18-2012, 10:14 AM
I wouldn't use the location of the shape, but give it a specific name (Or, add a 'Tag' property) such as 'Flag'.

Before you add your new shape, loop through the shapes on the slide and if you find one with the proper name or tag, then delete it. And set the name/tag property when you create the new shape.

The Name property is very easy and straigtforward; Using a 'Tag' requires a little more work, but adds a few benefits - you can add multiple tags, the tags are not directly editable by the user, and the tags are a name/value pair, so you could create a Tag named 'Flag' for your shape, and the value could be the type of flag, which could help allow you to identify which flag is used.

I Used ID and it worked. Thanks again!