Deselect objects from a selection

J

JS

Hi All,

I need to manipulate, via a VBA macro, several objects I've already selected
before running the macro. However, In this selection, there are several
objects that need to be exclided from the selection (and from being
manipulated by the macro). I've created some code to do this but I've run
into a problem, I don't know how to deselect object from a selection.... Con
someone please give me a clue?
Thanks so much! JS

Sub DoSomething ()
Dim oSlide As Slide, Shp As Shape
Set xxx = ActiveWindow.Selection.ShapeRange
ActiveWindow.Selection.Unselect
For Each Shp In xxx
If Shp.Type <> msoLine Then
xyz.ShapeRange.Add Shp '<== THIS DOESN'T WORK
End If
Next
xyz.Select
End Sub
 
D

David M. Marcovitz

It doesn't seem to be very elegant, but it seems to work. You might want
to scroll through the tags and delete them as well in case you want to
run the procedure again with different selections:

Sub DoSomething()
Dim Shp As Shape
Dim curSlide As Long

For Each Shp In ActiveWindow.Selection.ShapeRange
If Shp.Type <> msoLine Then
Shp.Tags.Add "SelectIt", "yes"
End If
Next Shp
curSlide = ActiveWindow.Selection.SlideRange(1).SlideIndex
ActiveWindow.Selection.Unselect
For Each Shp In ActivePresentation.Slides(curSlide).Shapes
If Shp.Tags("SelectIt") = "yes" Then
Shp.Select (msoFalse)
End If
Next Shp
End Sub

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
S

Steve Rindsberg

Hi All,

I need to manipulate, via a VBA macro, several objects I've already selected
before running the macro. However, In this selection, there are several
objects that need to be exclided from the selection (and from being
manipulated by the macro). I've created some code to do this but I've run
into a problem, I don't know how to deselect object from a selection.... Con
someone please give me a clue?

For starters, it's always a good idea to include

Option Explicit

at the beginning of every module. This forces you to declare all of your
variables, which can be a minor nuisance that prevents major problems.
Then declare the type for xxx (ShapeRange, no?)
Sub DoSomething ()
Dim oSlide As Slide, Shp As Shape
Set xxx = ActiveWindow.Selection.ShapeRange
ActiveWindow.Selection.Unselect
For Each Shp In xxx
If Shp.Type <> msoLine Then
xyz.ShapeRange.Add Shp '<== THIS DOESN'T WORK
End If
Next
xyz.Select
End Sub

Do you really need stuff selected at the end?
Would something like this work instead?

Sub DoSomething ()
Dim oSlide As Slide, Shp As Shape
For each Shp in ActiveWindow.Selection.ShapeRange
If Shp.Type <> msoLine Then
' do whatever you want to do here with the shape
End If
Next ' Shp
End Sub
 
S

Shyam Pillai

JS,
I might be simpler just to create an array containing the index numbers of
the desired shape and create a shape range from it.

Set oShpRng = ActivePresentation.Slides(1).Shapes.Range(Array(1, 6,7,8))

Regards,
Shyam Pillai

OfficeTips: http://skp.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top