Get shape index in powerpoint VBA
up vote
0
down vote
favorite
I hope this is a super simple question but for some reason i cant figure it out.
I need to delete a subset of the selected shapes on a powerpoint slide using VBA. I can do this using:
ActivePresentation.Slides(1).Shapes.Range(_Index_).Delete
Where _Index_ is either an array of shape indexes (integers) or shape names (stings).
Since the shape names are not unique (and people i am making this macro for have a nasty habit of having multiple shapes with the same name) i need to rely on the shape index number. My problem is i dont know how to get the index number of a given shape.
I can only see how i get the shape name or shape ID using:
ActiveWindow.Selection.ShapeRange(IdNum).Name
ActiveWindow.Selection.ShapeRange(IdNum).ID
So my question is: How do i get the shape index of selected shapes?
vba powerpoint powerpoint-vba
|
show 4 more comments
up vote
0
down vote
favorite
I hope this is a super simple question but for some reason i cant figure it out.
I need to delete a subset of the selected shapes on a powerpoint slide using VBA. I can do this using:
ActivePresentation.Slides(1).Shapes.Range(_Index_).Delete
Where _Index_ is either an array of shape indexes (integers) or shape names (stings).
Since the shape names are not unique (and people i am making this macro for have a nasty habit of having multiple shapes with the same name) i need to rely on the shape index number. My problem is i dont know how to get the index number of a given shape.
I can only see how i get the shape name or shape ID using:
ActiveWindow.Selection.ShapeRange(IdNum).Name
ActiveWindow.Selection.ShapeRange(IdNum).ID
So my question is: How do i get the shape index of selected shapes?
vba powerpoint powerpoint-vba
The id should give the order they were added to the slide.
– QHarr
Nov 10 at 20:33
Yes but how can i translate an ID into an index? The Index is always numbered 1 to number of shapes on slide while ID can be anything with gaps in between (e.g., it could be that index 1 has ID 5 and index 2 has ID 211). It seems like there should be an easy way to just get the index..
– Peter
Nov 10 at 21:08
I don't think a separate list of indices is maintained for the Shapes collection. You could write a loop over the shapes collection to assign names you can use to differentiate.
– QHarr
Nov 10 at 21:19
" My problem is i dont know how to get the index number of a given shape." If by "given" you mean selected, then ActiveWindow.Selection.ShapeRange(1)..ZOrderPosition will give you the index.
– Steve Rindsberg
Nov 11 at 16:00
Steve Rindsberg this was exactly what i needed! Thanks a lot! Im not exactly sure how this site works in terms of credit for answers but will you leave your comment as an answer so i can mark it as solved? Thanks again.
– Peter
Nov 12 at 9:03
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I hope this is a super simple question but for some reason i cant figure it out.
I need to delete a subset of the selected shapes on a powerpoint slide using VBA. I can do this using:
ActivePresentation.Slides(1).Shapes.Range(_Index_).Delete
Where _Index_ is either an array of shape indexes (integers) or shape names (stings).
Since the shape names are not unique (and people i am making this macro for have a nasty habit of having multiple shapes with the same name) i need to rely on the shape index number. My problem is i dont know how to get the index number of a given shape.
I can only see how i get the shape name or shape ID using:
ActiveWindow.Selection.ShapeRange(IdNum).Name
ActiveWindow.Selection.ShapeRange(IdNum).ID
So my question is: How do i get the shape index of selected shapes?
vba powerpoint powerpoint-vba
I hope this is a super simple question but for some reason i cant figure it out.
I need to delete a subset of the selected shapes on a powerpoint slide using VBA. I can do this using:
ActivePresentation.Slides(1).Shapes.Range(_Index_).Delete
Where _Index_ is either an array of shape indexes (integers) or shape names (stings).
Since the shape names are not unique (and people i am making this macro for have a nasty habit of having multiple shapes with the same name) i need to rely on the shape index number. My problem is i dont know how to get the index number of a given shape.
I can only see how i get the shape name or shape ID using:
ActiveWindow.Selection.ShapeRange(IdNum).Name
ActiveWindow.Selection.ShapeRange(IdNum).ID
So my question is: How do i get the shape index of selected shapes?
vba powerpoint powerpoint-vba
vba powerpoint powerpoint-vba
edited Nov 12 at 9:11
asked Nov 10 at 19:57
Peter
32
32
The id should give the order they were added to the slide.
– QHarr
Nov 10 at 20:33
Yes but how can i translate an ID into an index? The Index is always numbered 1 to number of shapes on slide while ID can be anything with gaps in between (e.g., it could be that index 1 has ID 5 and index 2 has ID 211). It seems like there should be an easy way to just get the index..
– Peter
Nov 10 at 21:08
I don't think a separate list of indices is maintained for the Shapes collection. You could write a loop over the shapes collection to assign names you can use to differentiate.
– QHarr
Nov 10 at 21:19
" My problem is i dont know how to get the index number of a given shape." If by "given" you mean selected, then ActiveWindow.Selection.ShapeRange(1)..ZOrderPosition will give you the index.
– Steve Rindsberg
Nov 11 at 16:00
Steve Rindsberg this was exactly what i needed! Thanks a lot! Im not exactly sure how this site works in terms of credit for answers but will you leave your comment as an answer so i can mark it as solved? Thanks again.
– Peter
Nov 12 at 9:03
|
show 4 more comments
The id should give the order they were added to the slide.
– QHarr
Nov 10 at 20:33
Yes but how can i translate an ID into an index? The Index is always numbered 1 to number of shapes on slide while ID can be anything with gaps in between (e.g., it could be that index 1 has ID 5 and index 2 has ID 211). It seems like there should be an easy way to just get the index..
– Peter
Nov 10 at 21:08
I don't think a separate list of indices is maintained for the Shapes collection. You could write a loop over the shapes collection to assign names you can use to differentiate.
– QHarr
Nov 10 at 21:19
" My problem is i dont know how to get the index number of a given shape." If by "given" you mean selected, then ActiveWindow.Selection.ShapeRange(1)..ZOrderPosition will give you the index.
– Steve Rindsberg
Nov 11 at 16:00
Steve Rindsberg this was exactly what i needed! Thanks a lot! Im not exactly sure how this site works in terms of credit for answers but will you leave your comment as an answer so i can mark it as solved? Thanks again.
– Peter
Nov 12 at 9:03
The id should give the order they were added to the slide.
– QHarr
Nov 10 at 20:33
The id should give the order they were added to the slide.
– QHarr
Nov 10 at 20:33
Yes but how can i translate an ID into an index? The Index is always numbered 1 to number of shapes on slide while ID can be anything with gaps in between (e.g., it could be that index 1 has ID 5 and index 2 has ID 211). It seems like there should be an easy way to just get the index..
– Peter
Nov 10 at 21:08
Yes but how can i translate an ID into an index? The Index is always numbered 1 to number of shapes on slide while ID can be anything with gaps in between (e.g., it could be that index 1 has ID 5 and index 2 has ID 211). It seems like there should be an easy way to just get the index..
– Peter
Nov 10 at 21:08
I don't think a separate list of indices is maintained for the Shapes collection. You could write a loop over the shapes collection to assign names you can use to differentiate.
– QHarr
Nov 10 at 21:19
I don't think a separate list of indices is maintained for the Shapes collection. You could write a loop over the shapes collection to assign names you can use to differentiate.
– QHarr
Nov 10 at 21:19
" My problem is i dont know how to get the index number of a given shape." If by "given" you mean selected, then ActiveWindow.Selection.ShapeRange(1)..ZOrderPosition will give you the index.
– Steve Rindsberg
Nov 11 at 16:00
" My problem is i dont know how to get the index number of a given shape." If by "given" you mean selected, then ActiveWindow.Selection.ShapeRange(1)..ZOrderPosition will give you the index.
– Steve Rindsberg
Nov 11 at 16:00
Steve Rindsberg this was exactly what i needed! Thanks a lot! Im not exactly sure how this site works in terms of credit for answers but will you leave your comment as an answer so i can mark it as solved? Thanks again.
– Peter
Nov 12 at 9:03
Steve Rindsberg this was exactly what i needed! Thanks a lot! Im not exactly sure how this site works in terms of credit for answers but will you leave your comment as an answer so i can mark it as solved? Thanks again.
– Peter
Nov 12 at 9:03
|
show 4 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
When you group a selection of shapes, the group becomes a new shape appended to the end of the previous z-order position. All of the individual shapes within the group are appended to the z-order after the group shape itself.
I can't find a way of determining which individual item within a group is selected (sub-selected, I guess we should say, since the original parent group remains selected and that's what PPT returns when you query ActiveWindow.Selection.ShapeRange(1).
To identify the currently subselected item within a group, you can use this as a starting point:
Sub WorkWithSubSelectedShapes()
' Do stuff with sub-selected shapes within a group
' Courtesy of Andy Pope
Dim oSh As Shape
Dim oGSh As Shape
Dim x As Long
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Do something with each shape in the group:
For Each oGSh In oSh.GroupItems
Debug.Print oGSh.TextFrame.TextRange.Text
Next
' Now do something with each SUB-SELECTED
' shape within the group
With ActiveWindow.Selection.ChildShapeRange
For x = 1 To .Count
Debug.Print .Item(x).Name
Debug.Print .Item(x).TextFrame.TextRange.Text
Next
End With
End Sub
Here's some code that may help generally in processing shapes/groups. It takes account of the fact that there might be groups within groups (within groups (within groups)) ...
Sub ProcessShapes()
Dim oSh As Shape
For Each oSh In ActivePresentation.Slides(1).Shapes
If oSh.Type = msoGroup Then
Debug.Print "GROUP" & vbTab & oSh.Name & vbTab & oSh.ZOrderPosition
Call DealWithGroup(oSh)
Else
Debug.Print oSh.Name & vbTab & oSh.ZOrderPosition
End If
Next
End Sub
Sub DealWithGroup(oSh As Shape)
Dim x As Long
For x = 1 To oSh.GroupItems.Count
If oSh.GroupItems(x).Type = msoGroup Then
Call DealWithGroup(oSh.GroupItems(x))
Else
Debug.Print "GROUP ITEM" & vbTab & oSh.GroupItems(x).Name & vbTab & oSh.GroupItems(x).ZOrderPosition
End If
Next
End Sub
And to answer Peter's further (excellent) question, this should work:
Sub TestIndexOf()
MsgBox IndexOf(ActiveWindow.Selection.ShapeRange(1))
End Sub
Function IndexOf(oSh As Shape) As Long
Dim x As Long
With ActiveWindow.Selection.SlideRange.Shapes
For x = 1 To .Count
If .Item(x).Name = oSh.Name Then
' Found it, report it
IndexOf = x
End If
Next
End With
End Function
1
Thanks @SteveRindsberg I had hoped for a more clean way (e.g., like ZOrderPosition without having to loop through shapes) but i guess this gets the job done. One small edit i would make is to change it to compare .ID instead of .Name since (as far as i understand) the ID is unique while the Name is not. Then it will also work if multiple shapes on the slide has the same name.
– Peter
Nov 14 at 22:58
@Peter Good point. While names are theoretically unique, PowerPoint has a habit of sometimes creating multiple same-named shape, which can cause all sorts of odd problems.
– Steve Rindsberg
Nov 15 at 19:02
add a comment |
up vote
0
down vote
Try the few lines of code and yow will get names of all the shapes in immediate window (Cttl+G to view Immediate window)
Dim shp As Shape, I As Integer
For Each shp In ActivePresentation.Slides(1).Shapes
I = I + 1
Debug.Print "Index=" & I & " Name= " & shp.Name & " ID= " & shp.Id & " Type= " & shp.Type
Next
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
When you group a selection of shapes, the group becomes a new shape appended to the end of the previous z-order position. All of the individual shapes within the group are appended to the z-order after the group shape itself.
I can't find a way of determining which individual item within a group is selected (sub-selected, I guess we should say, since the original parent group remains selected and that's what PPT returns when you query ActiveWindow.Selection.ShapeRange(1).
To identify the currently subselected item within a group, you can use this as a starting point:
Sub WorkWithSubSelectedShapes()
' Do stuff with sub-selected shapes within a group
' Courtesy of Andy Pope
Dim oSh As Shape
Dim oGSh As Shape
Dim x As Long
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Do something with each shape in the group:
For Each oGSh In oSh.GroupItems
Debug.Print oGSh.TextFrame.TextRange.Text
Next
' Now do something with each SUB-SELECTED
' shape within the group
With ActiveWindow.Selection.ChildShapeRange
For x = 1 To .Count
Debug.Print .Item(x).Name
Debug.Print .Item(x).TextFrame.TextRange.Text
Next
End With
End Sub
Here's some code that may help generally in processing shapes/groups. It takes account of the fact that there might be groups within groups (within groups (within groups)) ...
Sub ProcessShapes()
Dim oSh As Shape
For Each oSh In ActivePresentation.Slides(1).Shapes
If oSh.Type = msoGroup Then
Debug.Print "GROUP" & vbTab & oSh.Name & vbTab & oSh.ZOrderPosition
Call DealWithGroup(oSh)
Else
Debug.Print oSh.Name & vbTab & oSh.ZOrderPosition
End If
Next
End Sub
Sub DealWithGroup(oSh As Shape)
Dim x As Long
For x = 1 To oSh.GroupItems.Count
If oSh.GroupItems(x).Type = msoGroup Then
Call DealWithGroup(oSh.GroupItems(x))
Else
Debug.Print "GROUP ITEM" & vbTab & oSh.GroupItems(x).Name & vbTab & oSh.GroupItems(x).ZOrderPosition
End If
Next
End Sub
And to answer Peter's further (excellent) question, this should work:
Sub TestIndexOf()
MsgBox IndexOf(ActiveWindow.Selection.ShapeRange(1))
End Sub
Function IndexOf(oSh As Shape) As Long
Dim x As Long
With ActiveWindow.Selection.SlideRange.Shapes
For x = 1 To .Count
If .Item(x).Name = oSh.Name Then
' Found it, report it
IndexOf = x
End If
Next
End With
End Function
1
Thanks @SteveRindsberg I had hoped for a more clean way (e.g., like ZOrderPosition without having to loop through shapes) but i guess this gets the job done. One small edit i would make is to change it to compare .ID instead of .Name since (as far as i understand) the ID is unique while the Name is not. Then it will also work if multiple shapes on the slide has the same name.
– Peter
Nov 14 at 22:58
@Peter Good point. While names are theoretically unique, PowerPoint has a habit of sometimes creating multiple same-named shape, which can cause all sorts of odd problems.
– Steve Rindsberg
Nov 15 at 19:02
add a comment |
up vote
0
down vote
accepted
When you group a selection of shapes, the group becomes a new shape appended to the end of the previous z-order position. All of the individual shapes within the group are appended to the z-order after the group shape itself.
I can't find a way of determining which individual item within a group is selected (sub-selected, I guess we should say, since the original parent group remains selected and that's what PPT returns when you query ActiveWindow.Selection.ShapeRange(1).
To identify the currently subselected item within a group, you can use this as a starting point:
Sub WorkWithSubSelectedShapes()
' Do stuff with sub-selected shapes within a group
' Courtesy of Andy Pope
Dim oSh As Shape
Dim oGSh As Shape
Dim x As Long
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Do something with each shape in the group:
For Each oGSh In oSh.GroupItems
Debug.Print oGSh.TextFrame.TextRange.Text
Next
' Now do something with each SUB-SELECTED
' shape within the group
With ActiveWindow.Selection.ChildShapeRange
For x = 1 To .Count
Debug.Print .Item(x).Name
Debug.Print .Item(x).TextFrame.TextRange.Text
Next
End With
End Sub
Here's some code that may help generally in processing shapes/groups. It takes account of the fact that there might be groups within groups (within groups (within groups)) ...
Sub ProcessShapes()
Dim oSh As Shape
For Each oSh In ActivePresentation.Slides(1).Shapes
If oSh.Type = msoGroup Then
Debug.Print "GROUP" & vbTab & oSh.Name & vbTab & oSh.ZOrderPosition
Call DealWithGroup(oSh)
Else
Debug.Print oSh.Name & vbTab & oSh.ZOrderPosition
End If
Next
End Sub
Sub DealWithGroup(oSh As Shape)
Dim x As Long
For x = 1 To oSh.GroupItems.Count
If oSh.GroupItems(x).Type = msoGroup Then
Call DealWithGroup(oSh.GroupItems(x))
Else
Debug.Print "GROUP ITEM" & vbTab & oSh.GroupItems(x).Name & vbTab & oSh.GroupItems(x).ZOrderPosition
End If
Next
End Sub
And to answer Peter's further (excellent) question, this should work:
Sub TestIndexOf()
MsgBox IndexOf(ActiveWindow.Selection.ShapeRange(1))
End Sub
Function IndexOf(oSh As Shape) As Long
Dim x As Long
With ActiveWindow.Selection.SlideRange.Shapes
For x = 1 To .Count
If .Item(x).Name = oSh.Name Then
' Found it, report it
IndexOf = x
End If
Next
End With
End Function
1
Thanks @SteveRindsberg I had hoped for a more clean way (e.g., like ZOrderPosition without having to loop through shapes) but i guess this gets the job done. One small edit i would make is to change it to compare .ID instead of .Name since (as far as i understand) the ID is unique while the Name is not. Then it will also work if multiple shapes on the slide has the same name.
– Peter
Nov 14 at 22:58
@Peter Good point. While names are theoretically unique, PowerPoint has a habit of sometimes creating multiple same-named shape, which can cause all sorts of odd problems.
– Steve Rindsberg
Nov 15 at 19:02
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
When you group a selection of shapes, the group becomes a new shape appended to the end of the previous z-order position. All of the individual shapes within the group are appended to the z-order after the group shape itself.
I can't find a way of determining which individual item within a group is selected (sub-selected, I guess we should say, since the original parent group remains selected and that's what PPT returns when you query ActiveWindow.Selection.ShapeRange(1).
To identify the currently subselected item within a group, you can use this as a starting point:
Sub WorkWithSubSelectedShapes()
' Do stuff with sub-selected shapes within a group
' Courtesy of Andy Pope
Dim oSh As Shape
Dim oGSh As Shape
Dim x As Long
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Do something with each shape in the group:
For Each oGSh In oSh.GroupItems
Debug.Print oGSh.TextFrame.TextRange.Text
Next
' Now do something with each SUB-SELECTED
' shape within the group
With ActiveWindow.Selection.ChildShapeRange
For x = 1 To .Count
Debug.Print .Item(x).Name
Debug.Print .Item(x).TextFrame.TextRange.Text
Next
End With
End Sub
Here's some code that may help generally in processing shapes/groups. It takes account of the fact that there might be groups within groups (within groups (within groups)) ...
Sub ProcessShapes()
Dim oSh As Shape
For Each oSh In ActivePresentation.Slides(1).Shapes
If oSh.Type = msoGroup Then
Debug.Print "GROUP" & vbTab & oSh.Name & vbTab & oSh.ZOrderPosition
Call DealWithGroup(oSh)
Else
Debug.Print oSh.Name & vbTab & oSh.ZOrderPosition
End If
Next
End Sub
Sub DealWithGroup(oSh As Shape)
Dim x As Long
For x = 1 To oSh.GroupItems.Count
If oSh.GroupItems(x).Type = msoGroup Then
Call DealWithGroup(oSh.GroupItems(x))
Else
Debug.Print "GROUP ITEM" & vbTab & oSh.GroupItems(x).Name & vbTab & oSh.GroupItems(x).ZOrderPosition
End If
Next
End Sub
And to answer Peter's further (excellent) question, this should work:
Sub TestIndexOf()
MsgBox IndexOf(ActiveWindow.Selection.ShapeRange(1))
End Sub
Function IndexOf(oSh As Shape) As Long
Dim x As Long
With ActiveWindow.Selection.SlideRange.Shapes
For x = 1 To .Count
If .Item(x).Name = oSh.Name Then
' Found it, report it
IndexOf = x
End If
Next
End With
End Function
When you group a selection of shapes, the group becomes a new shape appended to the end of the previous z-order position. All of the individual shapes within the group are appended to the z-order after the group shape itself.
I can't find a way of determining which individual item within a group is selected (sub-selected, I guess we should say, since the original parent group remains selected and that's what PPT returns when you query ActiveWindow.Selection.ShapeRange(1).
To identify the currently subselected item within a group, you can use this as a starting point:
Sub WorkWithSubSelectedShapes()
' Do stuff with sub-selected shapes within a group
' Courtesy of Andy Pope
Dim oSh As Shape
Dim oGSh As Shape
Dim x As Long
Set oSh = ActiveWindow.Selection.ShapeRange(1)
' Do something with each shape in the group:
For Each oGSh In oSh.GroupItems
Debug.Print oGSh.TextFrame.TextRange.Text
Next
' Now do something with each SUB-SELECTED
' shape within the group
With ActiveWindow.Selection.ChildShapeRange
For x = 1 To .Count
Debug.Print .Item(x).Name
Debug.Print .Item(x).TextFrame.TextRange.Text
Next
End With
End Sub
Here's some code that may help generally in processing shapes/groups. It takes account of the fact that there might be groups within groups (within groups (within groups)) ...
Sub ProcessShapes()
Dim oSh As Shape
For Each oSh In ActivePresentation.Slides(1).Shapes
If oSh.Type = msoGroup Then
Debug.Print "GROUP" & vbTab & oSh.Name & vbTab & oSh.ZOrderPosition
Call DealWithGroup(oSh)
Else
Debug.Print oSh.Name & vbTab & oSh.ZOrderPosition
End If
Next
End Sub
Sub DealWithGroup(oSh As Shape)
Dim x As Long
For x = 1 To oSh.GroupItems.Count
If oSh.GroupItems(x).Type = msoGroup Then
Call DealWithGroup(oSh.GroupItems(x))
Else
Debug.Print "GROUP ITEM" & vbTab & oSh.GroupItems(x).Name & vbTab & oSh.GroupItems(x).ZOrderPosition
End If
Next
End Sub
And to answer Peter's further (excellent) question, this should work:
Sub TestIndexOf()
MsgBox IndexOf(ActiveWindow.Selection.ShapeRange(1))
End Sub
Function IndexOf(oSh As Shape) As Long
Dim x As Long
With ActiveWindow.Selection.SlideRange.Shapes
For x = 1 To .Count
If .Item(x).Name = oSh.Name Then
' Found it, report it
IndexOf = x
End If
Next
End With
End Function
edited Nov 14 at 15:15
answered Nov 12 at 15:42
Steve Rindsberg
10k11526
10k11526
1
Thanks @SteveRindsberg I had hoped for a more clean way (e.g., like ZOrderPosition without having to loop through shapes) but i guess this gets the job done. One small edit i would make is to change it to compare .ID instead of .Name since (as far as i understand) the ID is unique while the Name is not. Then it will also work if multiple shapes on the slide has the same name.
– Peter
Nov 14 at 22:58
@Peter Good point. While names are theoretically unique, PowerPoint has a habit of sometimes creating multiple same-named shape, which can cause all sorts of odd problems.
– Steve Rindsberg
Nov 15 at 19:02
add a comment |
1
Thanks @SteveRindsberg I had hoped for a more clean way (e.g., like ZOrderPosition without having to loop through shapes) but i guess this gets the job done. One small edit i would make is to change it to compare .ID instead of .Name since (as far as i understand) the ID is unique while the Name is not. Then it will also work if multiple shapes on the slide has the same name.
– Peter
Nov 14 at 22:58
@Peter Good point. While names are theoretically unique, PowerPoint has a habit of sometimes creating multiple same-named shape, which can cause all sorts of odd problems.
– Steve Rindsberg
Nov 15 at 19:02
1
1
Thanks @SteveRindsberg I had hoped for a more clean way (e.g., like ZOrderPosition without having to loop through shapes) but i guess this gets the job done. One small edit i would make is to change it to compare .ID instead of .Name since (as far as i understand) the ID is unique while the Name is not. Then it will also work if multiple shapes on the slide has the same name.
– Peter
Nov 14 at 22:58
Thanks @SteveRindsberg I had hoped for a more clean way (e.g., like ZOrderPosition without having to loop through shapes) but i guess this gets the job done. One small edit i would make is to change it to compare .ID instead of .Name since (as far as i understand) the ID is unique while the Name is not. Then it will also work if multiple shapes on the slide has the same name.
– Peter
Nov 14 at 22:58
@Peter Good point. While names are theoretically unique, PowerPoint has a habit of sometimes creating multiple same-named shape, which can cause all sorts of odd problems.
– Steve Rindsberg
Nov 15 at 19:02
@Peter Good point. While names are theoretically unique, PowerPoint has a habit of sometimes creating multiple same-named shape, which can cause all sorts of odd problems.
– Steve Rindsberg
Nov 15 at 19:02
add a comment |
up vote
0
down vote
Try the few lines of code and yow will get names of all the shapes in immediate window (Cttl+G to view Immediate window)
Dim shp As Shape, I As Integer
For Each shp In ActivePresentation.Slides(1).Shapes
I = I + 1
Debug.Print "Index=" & I & " Name= " & shp.Name & " ID= " & shp.Id & " Type= " & shp.Type
Next
add a comment |
up vote
0
down vote
Try the few lines of code and yow will get names of all the shapes in immediate window (Cttl+G to view Immediate window)
Dim shp As Shape, I As Integer
For Each shp In ActivePresentation.Slides(1).Shapes
I = I + 1
Debug.Print "Index=" & I & " Name= " & shp.Name & " ID= " & shp.Id & " Type= " & shp.Type
Next
add a comment |
up vote
0
down vote
up vote
0
down vote
Try the few lines of code and yow will get names of all the shapes in immediate window (Cttl+G to view Immediate window)
Dim shp As Shape, I As Integer
For Each shp In ActivePresentation.Slides(1).Shapes
I = I + 1
Debug.Print "Index=" & I & " Name= " & shp.Name & " ID= " & shp.Id & " Type= " & shp.Type
Next
Try the few lines of code and yow will get names of all the shapes in immediate window (Cttl+G to view Immediate window)
Dim shp As Shape, I As Integer
For Each shp In ActivePresentation.Slides(1).Shapes
I = I + 1
Debug.Print "Index=" & I & " Name= " & shp.Name & " ID= " & shp.Id & " Type= " & shp.Type
Next
answered Nov 11 at 0:49
Ahmed AU
55528
55528
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242865%2fget-shape-index-in-powerpoint-vba%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The id should give the order they were added to the slide.
– QHarr
Nov 10 at 20:33
Yes but how can i translate an ID into an index? The Index is always numbered 1 to number of shapes on slide while ID can be anything with gaps in between (e.g., it could be that index 1 has ID 5 and index 2 has ID 211). It seems like there should be an easy way to just get the index..
– Peter
Nov 10 at 21:08
I don't think a separate list of indices is maintained for the Shapes collection. You could write a loop over the shapes collection to assign names you can use to differentiate.
– QHarr
Nov 10 at 21:19
" My problem is i dont know how to get the index number of a given shape." If by "given" you mean selected, then ActiveWindow.Selection.ShapeRange(1)..ZOrderPosition will give you the index.
– Steve Rindsberg
Nov 11 at 16:00
Steve Rindsberg this was exactly what i needed! Thanks a lot! Im not exactly sure how this site works in terms of credit for answers but will you leave your comment as an answer so i can mark it as solved? Thanks again.
– Peter
Nov 12 at 9:03