#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 33
Default Moving Shapes

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Moving Shapes

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
  #3   Report Post  
Posted to microsoft.public.excel.misc
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
.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Moving Shapes

To name it, you can select the shape (I like to rightclick on it), then use the
namebox to the left of the formula bar. Remember to hit enter when you're done
with the name.

But no, this will take a random moveable object and place it over the unmoveable
object that was clicked.

That's what I thought you meant when you wrote that...

This would be a random selection and
placement of shapes (e.g., any movable shape can be moved to any unmovable
shape).


I think you're going to have to use two macros. One that indicates what shape
should be used and one that does the real work.

For this code, you don't have to use nice names. You just have to make sure
that you've assigned the macro to the correct shapes.

Option Explicit
Dim MovShape As Shape
Sub JustBeep() 'Should be BeepAndSet(), since it's doing 2 things
Beep
Set MovShape = ActiveSheet.Shapes(Application.Caller)
End Sub
Sub DoTheMove()

Dim UnMovShape As Shape
Dim ALittleBit As Double

If MovShape Is Nothing Then
MsgBox "Please click on one of the moveable shapes first!"
Exit Sub
End If

Set UnMovShape = ActiveSheet.Shapes(Application.Caller)

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

'clear out for next time
'or reuse that same shape???
Set MovShape = Nothing 'this clears it.

End Sub


Preschool Mike wrote:

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
.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel document with shapes on it but the shapes do not print [email protected] Excel Worksheet Functions 2 October 22nd 09 06:17 PM
inserted shapes keep moving Stephid707 Excel Discussion (Misc queries) 1 February 16th 09 06:37 PM
Shapes and Arrows Moving dpparman Excel Discussion (Misc queries) 1 August 20th 08 01:04 AM
Naming Auto Shapes and Creating new Shapes AL2000 Excel Discussion (Misc queries) 3 September 10th 07 04:12 AM
Moving Shapes with the mouse pan65 New Users to Excel 0 August 13th 06 06:35 AM


All times are GMT +1. The time now is 08:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"