PDA

View Full Version : Solved: Get the name of a new autoshape rectangle



boy_plunder
08-13-2008, 06:07 AM
Bare with me while I explain this one.

I have scripted a number of macros that add a rectangle shape to a page, position it, colours it in some cases, and applies a user selected picture to the rectangle's fill. Using the Fill effects > background setting. All works like a dream.

The problem is that you can't set the value of the little checkbox for the added picture to lock its aspect ratio where you set the picture. Even if you record the setting of this, VBA doesn't recognise it. This means that the picture is stretched to the rectangle.

So... I have a fixed rectangle on the cover page, so I am now trying to pick up the formatting of that one and apply it to a new rectangle I use in the other macros. I have proved this can be done, and applies the little checkbox value I need. The problem I am currently left with, is how can I get the name of the new rectangle to apply the formatting to?

Few! Anybody with a solution for getting the name of a shape I have just created?

:banghead:

TomSchreiner
08-13-2008, 07:07 PM
You provide yourself with a reference when you add the shape and then assign a name in your code. Post your code. Expecially the snippet that adds the shape...

Here are three examples...

With ActiveSheet.Shapes.AddShape(msoShapeRectangle, 203.25, 310.5, 51.75, 29.25)
.Name = "NewShape1"
End With

ActiveSheet.Shapes.AddShape(msoShapeRectangle, 203.25, 310.5, 51.75, 29.25).Name = "NewShape2"

Dim sh As Object
Set sh = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 203.25, 310.5, 51.75, 29.25)
sh.Name = "NewShape3"