Move Shapes with VB?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to move shapes with VB? That is, can I program a command button to move a shape or piece of clip art ? I am thinking of a board game where depending upon certain inputs, I will be able to move a shape any number of "spaces"
Thanks
 
Yes,

Use the .top and .left properties of a shape.
Or look on Shyam's web page www.mvps.org/skp/ and look for How to
determine which shape was clicked. That's let you get the properties
of a checkerboard which you could use to move your checkers to.

Brian Reilly, PowerPoint MVP
 
Yes, this is pretty easy. I didn't put this in my book, but now I wish I
did. Here are some procedures to play with. The first one move shape 1
on the current slide to location 5, 5. The second procedure asks where
you want to move shape 1 on the current slide to and moves it there
(assuming you ask to move it from 0 to 500). The last two procdures
(along with the Dim at the top) are a large part of what you need to do
for your checkerboard. Create a checkerboard with a bunch of squares.
Each square should have the Action Settings set to run the macro MoveTo.
Create some checkers and set their Action Settings to run the macro
MoveHim. Click on a checker, and it will turn green. Click on a square
and the checker will turn back to black and move to the square you
clicked on.

Of course, you will need to add a bunch of stuff to make sure that there
isn't a checker already there or that the move follows the rules, and you
will need to work out some other details, but this is the heart of what
you want.

If you want, I can send you the file that I made to play with this (email
me, but remove NOSPAM from my email address). Be glad you asked today
and not yesterday. Yesterday, I was too busy grading 20-page papers to
have this much fun.

Dim movableChecker As shape

Sub MoveToFiveFive()
ActivePresentation.SlideShowWindow.View.Slide.Shapes(1).Top = 5
ActivePresentation.SlideShowWindow.View.Slide.Shapes(1).Left = 5
End Sub

Sub AskAndMove()
myTop = InputBox("How far from the top?")
If myTop < 500 And myTop > 0 Then
myLeft = InputBox("How far from the left?")
If myLeft < 500 And myLeft > 0 Then
ActivePresentation.SlideShowWindow.View.Slide.Shapes(1) _
.Top = myTop
ActivePresentation.SlideShowWindow.View.Slide.Shapes(1) _
.Left = myLeft
Else
MsgBox _
"Don't move off the screen; you're too low or too high"
End If
Else
MsgBox _
"Don't move off the screen; you're too far left or right"
End If
End Sub

Sub MoveHim(theChecker As shape)
theChecker.Fill.ForeColor.RGB = vbGreen
Set movableChecker = theChecker
End Sub

Sub MoveTo(theSquare As shape)
movableChecker.Fill.ForeColor.RGB = vbBlack
movableChecker.Top = theSquare.Top + 3
movableChecker.Left = theSquare.Left + 3
End Sub


--
David M. Marcovitz, Ph.D.
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
Back
Top