Consulting

Results 1 to 2 of 2

Thread: Solved: Get the name of a new autoshape rectangle

  1. #1

    Solved: Get the name of a new autoshape rectangle

    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?


  2. #2
    VBAX Regular
    Joined
    Jul 2008
    Location
    Cincinnati, OH
    Posts
    86
    Location
    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...

    [VBA] 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"[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •