How to draw a object and erase it programmatically

  • Thread starter Thread starter Simon Lenn
  • Start date Start date
S

Simon Lenn

I want to draw a rectangle with a circle programmatically and then I
want to erase and draw the rectangle and circle at a different place
on the worksheet.

Appreciate if somebody can share the code segment for a routine for
this.

Thanks
Simon
 
Take a test sheet, start recording macro, do what you are trying to do, stop
recording, read the code


: I want to draw a rectangle with a circle programmatically and then I
: want to erase and draw the rectangle and circle at a different place
: on the worksheet.
:
: Appreciate if somebody can share the code segment for a routine for
: this.
:
: Thanks
: Simon
 
Sim on,

The macro recorder gives it

Dim myshape As Shape

Set myshape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 165#,
255.75, 192.75, 91.5)
myshape.Name = "My Rectangle"
Set myshape = ActiveSheet.Shapes.AddShape(msoShapeOval, 436.5, 333#,
67.5, 66.75)
myshape.Name = "My Circle"

and

With ActiveSheet
.Shapes("My Rectangle").Delete
.Shapes("My Circle").Delete
End With


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
You may want to group the circle and rectangle and instead of deleting, just
move them.

You could even add them multiple times and then toggle the visibility.
 
Copy and Delete Objects in Excel

Could this principle be used to insert a picture and then delete to replace with a different picture.

The effect I want to achieve is display a different picture depending on which number is input.

Or is there another way of doing this (lookup table with pictures)

Thanks

Kiteman
 

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