Consulting

Results 1 to 3 of 3

Thread: How to finad a shape by location?

  1. #1

    How to finad a shape by location?

    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

    [VBA]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[/VBA]

  2. #2
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    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.

  3. #3
    Quote Originally Posted by Cosmo
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •