Thread: Moving Shapes
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Preschool Mike Preschool Mike is offline
external usenet poster
 
Posts: 33
Default Moving Shapes

Thanks for your help but first a couple of follow up questions.

First, how do I name the shapes? Do I do this in the Name Manage? Second,
will this code allow the person to place the selected shape (one assigned to
Beep) in an unMovable shape of their choice? That's what I'm looking for.

--
Mike Mast
Special Education Preschool Teacher


"Dave Peterson" wrote:

It's kind of the same in excel, but different <vbg.

I added 10 shapes to a test worksheet. I named them nicely.

Mov1, Mov2, Mov3, Mov4 and Mov5
and UnMov1, ..., UnMov5

Then I put this code in a General module:

Option Explicit
Sub JustBeep()
Beep
End Sub
Sub DoTheMove()

Dim UnMovShape As Shape
Dim MovShape As Shape
Dim ALittleBit As Double

Dim myRnd As Long
Dim UpperBound As Long
Dim LowerBound As Long

LowerBound = 1
UpperBound = 5

Randomize
myRnd = Int((UpperBound - LowerBound + 1) * Rnd + LowerBound)


Set UnMovShape = ActiveSheet.Shapes(Application.Caller)

Set MovShape = ActiveSheet.Shapes("Mov" & myRnd)

ALittleBit = UnMovShape.Height * 0.2
With MovShape
.Top = UnMovShape.Top + (ALittleBit)
.Left = UnMovShape.Left + (ALittleBit)
.Width = UnMovShape.Width - (ALittleBit * 2)
.Height = UnMovShape.Height - (ALittleBit * 2)
End With

MovShape.ZOrder zordercmd:=msoBringToFront

End Sub

I assigned the "JustBeep" macro to each of the 5 moveable objects. And I
assigned the DoTheMove procedure to each of the unmoveable objects.

With the shape of the objects (I used buttons from the Forms toolbar) that I
used, the 20% reduction of the button size based on height worked nicely. You
may want something different -- based on .width or even an actual number????



Preschool Mike wrote:

Let me see if I can explain this correctly....I have 10 shapes/picutres on my
worksheet. Shapes 1 - 5 we'll call movable and shapes 6 - 10 unmovable.
What I'd like to happen is that by clicking on one of my movable shapes and
then by clicking on one of my unmovable shapes the movable shape moves on top
of or inside the unmovable shape. This would be a random selection and
placement of shapes (e.g., any movable shape can be moved to any unmovable
shape). Is this possible? I know how to do this in powerpoint but have no
clue with excel.

In powerpoint I would do something like this...
Dim myShape As Shape
'Assign the shape to be moved to this macro
Sub MoveThisShape(theShape As Shape)
Set myShape = theShape
End Sub

'Assign the shape that its moved to to this macro
Sub MoveShapeTo(thePlacementShape As Shape)
myShape.Top = thePlacementShape.Top + 1
myShape.Left = ThePlacementShape.Left + 1
End sub
--
Mike Mast
Special Education Preschool Teacher


--

Dave Peterson
.