Move an object not using increment property

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

Guest

I am setting up an excel sheet that will locate certain drawing objects based
on check boxes or radio buttions. Right now I have a lot of code that checks
the current location of the object and then uses the IncrementLeft and
IncrementTop properties to move the object. Does anyone know a different way
to do this. I would like to just locate the object at a point based on the
radio button or check box rather that having to check where it currently is
and adjusting the IncrementLeft and IncrementTop properties. Here is the code
for one of the objects I am currently using:

If Range("D114").Value = 3 Then
ActiveSheet.Shapes("Vise").Select
Selection.ShapeRange.IncrementLeft -270
Selection.ShapeRange.IncrementTop -111
Selection.ShapeRange.Flip msoFlipHorizontal
Else
If Range("D114").Value = 2 Then
ActiveSheet.Shapes("Vise").Select
Selection.ShapeRange.IncrementLeft -189
Selection.ShapeRange.Flip msoFlipHorizontal
End If
End If

This is an object with only to location possibilities. This expression grows
larger exponentially with location possibilities and I would like to have one
simple expression for each location.

Thank you in advance for any help you can give me.
 
You could write a subroutine

Select Case Range("D114").Value
Case 3
PositionObject ActiveSheet.Shapes("Vise"), -270, -111, msoFlipHorizontal
Case 4
PositionObject ActiveSheet.Shapes("Vise"), -189, 0, msoFlipHorizontal
End Select

End Sub



Sub PostitionObject(obj as Shape, lLeft as Long, lTop as Long, lFlip as
Long)
obj.ShapeRange.IncrementLeft lLeft
obj.shapeRange.IncrementTop lTop
obj.ShapeRange.Flip lFlip
End Sub
 
Great idea Tom, I will try that to see if I can make it work. It would sure
be nice if there was a property that you could set the location of an object
though, then i wouldn't have to select a case. Thanks again!
 
There are 2 properties

With ActiveSheet.Shapes("Vise")
.Left = Range("B9").Left
.Top = Range("B9").Top
End with

There is no single command that would place it over a specific cell.

The case statement or IF statements are because you want to go to different
locations based on the value in D114. Not sure how you can avoid coding
those different locations and using some type of decision construct to
determine where it goes.
 
I understand. my problem is that I want to go to an x and y coordinate. I
would like to be able to "locate" the object rather than "move it" if that
make sense. Say I have 3 radio buttons, 1 says "Top Left", 1 says "Bottom
Right", and the other says "Not Needed". I would like to write individual or
a single universal procedure that would locate the object in one of these
positions. Say the Not Needed is center. I know that using the increment
property, i must find out where the object is currently and move accordingly.
What would be nice is if I could just write a procedure that said:

If radio button "Top Left" is checked
Put the object at this location 20,20
If radio button "Bottom right is checked
Put the object at this location 200,200
If radio button "Not Needed" is checked
Put the object at this location 100,100

Currently, I am using the value of the radio buttons cell link to determine
the current position. It would be nice to not have to determine the current
position at all.

I tried the following on a sample sheet but keep getting the error:
Object doe not support this property or method. Can you see what I messed up?

Select Case Range("A1").Value
Case 1
PositionObject ActiveSheet.Shapes("Oval 1"), -212.25, -200
Range("A1").Value = 2
Case 2
PositionObject ActiveSheet.Shapes("Oval 1"), 212.25, 200
Range("A1").Value = 1
End Select

End Sub

Sub PositionObject(obj As Shape, ILeft As Long, ITop As Long)
obj.ShapeRange.IncrementLeft ILeft
obj.ShapeRange.IncrementTop ITop
End Sub
 
Sub Tester1()
Select Case Range("A1").Value
Case 1
PositionObject ActiveSheet.Shapes("Oval 1"), -212.25, -200
Range("A1").Value = 2
Case 2
PositionObject ActiveSheet.Shapes("Oval 1"), 212.25, 200
Range("A1").Value = 1
End Select

End Sub

Sub PositionObject(obj As Shape, ILeft As Long, ITop As Long)
obj.IncrementLeft ILeft
obj.IncrementTop ITop
End Sub

worked for me.
 
Strange, When I copied and pasted your "worked for me" is was fine. Thank you
so much for your help and ideas. These newsgroup things are awesome for me as
I am a novice.
 
Tom, Do you know what value I would use if I did not want the object to flip?
I have tried a 0 and a 1 but can't seem to get consistent results.
 
Sub PostitionObject(obj as Shape, lLeft as Long, lTop as Long, lFlip as
Long)
obj.ShapeRange.IncrementLeft lLeft
obj.shapeRange.IncrementTop lTop
if lFlip = 1 or lFlip = 0 then
obj.ShapeRange.Flip lFlip
End if
End Sub

so pass anything but a 1 or 0 and it won't flip.

You could make it an optional argument, but it seems to me it would be just
as easy to pass a -1 or something like that.
 

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

Back
Top