View Full Version : Shape id
saadamiens
01-25-2012, 10:48 AM
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
John Wilson
01-25-2012, 02:16 PM
The correct code would be:
ActiveWindow.Selection.ShapeRange(1).id**
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.
saadamiens
01-26-2012, 02:45 AM
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
John Wilson
01-26-2012, 03:40 AM
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.
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
saadamiens
01-26-2012, 04:02 AM
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.
saadamiens
01-26-2012, 04:21 AM
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 !
John Wilson
01-26-2012, 05:44 AM
Here's two way to look at all slides
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
You can also say
Set osld=ActiveWindow.View.Slide
to refer to the active slide
You would need to declere osld
Dim osld as Slide
saadamiens
01-26-2012, 08:51 AM
Thank you John
Have a great day
SAAD
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.