Consulting

Results 1 to 8 of 8

Thread: Shape id

  1. #1

    Shape id

    Hi everyone ,

    I am new in ppt vba and i would like to know how can i know the id of a shape once this shape is selected in a slide.
    i have tried this code
    ActiveWindow.Selection.ShapeRange.Id
    but the number it return is not the one that refers to the one i have selected
    Any help ?
    Thank you

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    The correct code would be:

    [vba]ActiveWindow.Selection.ShapeRange(1).id**[/vba]
    But it should return the correct ID if you don't get an error. How do you know that it is incorrect?

    ** Explaination!

    ShapeRanges do not have an ID , Shapes Do.

    ShapeRange(1) is the first shape in the Shaperange. SOME versions will accept your code as meaning this but some will error.
    Last edited by John Wilson; 01-25-2012 at 02:28 PM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Thank you john for your answer,

    What i need is the id of a shape once i select it with the mouse , my goal here is to use this id of this particular shape selected in order to put a shape on the top of it at the same seize and place.
    however if i do :
    i= ActiveWindow.Selection.ShapeRange(1).Id
    left = ActivePresentation.Slides(1).Shapes(i).left

    that doesn't work

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    You are confusing ID (line 1) with Index or ZOrder (line 2)

    They are quite different. You don't need to use ID at all just use an object variable to refer to the selected shape would be one way.

    [VBA]Sub Not_ID()
    Dim oshp As Shape ' this is an object variable
    Set oshp = ActiveWindow.Selection.ShapeRange(1) ' note you must use "Set"
    'add a star shape and move to position selected
    With ActiveWindow.Selection.SlideRange(1).Shapes.AddShape( _
    Type:=msoShape10pointStar, _
    Left:=oshp.Left, _
    Top:=oshp.Top, _
    Width:=oshp.Width, _
    Height:=oshp.Height)
    .Fill.ForeColor.RGB = vbYellow
    End With
    End Sub[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    Thank you so much , that's working like a charme
    Is there a way i can name a shape and use it's name in order to put an other shape on the top of it instead of using the
    ActiveWindow.Selection.ShapeRange(1)
    That would be easier for me if i have to loop the program in a lot of slide , to refer to the name of the shape instead of repeating the operation in every slide.

  6. #6
    I did it actually here is the code

    Sub essai()


    Dim left As Single
    Dim top As Single
    Dim width As Single
    Dim height As Single
    Dim oShp As Shape
    Dim i As Integer

    For i = 1 To 2

    For Each oShp In ActivePresentation.Slides(i).Shapes
    If oShp.Name = "saad" Then
    left = oShp.left
    top = oShp.top
    width = oShp.width
    height = oShp.height

    Set oPicture = ActiveWindow.Presentation.Slides(i).Shapes.AddPicture("c:\path", _
    msoFalse, msoTrue, left, top, width, height)
    End If


    Next oShp

    Next
    End Sub

    is there a way to say in the first loop for each slide ?
    and is it possible to know the activeslide instead of putting the number of the slide.
    Thank you for your help John !

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Here's two way to look at all slides
    [vba]For i = 1 To ActivePresentation.Slides.Count
    'as before

    'OR

    For Each osld In ActivePresentation.Slides
    For Each oshp In osld.Shapes
    ' ..... whateevr

    Next oshp
    Next osld[/vba]
    You can also say
    [vba]
    Set osld=ActiveWindow.View.Slide [/vba]
    to refer to the active slide

    You would need to declere osld

    Dim osld as Slide
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    Thank you John
    Have a great day
    SAAD

Posting Permissions

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