Create and place Auto Shape with VBA

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
349
Office Version
  1. 365
Platform
  1. Windows
I am working on a VBA program that I want to have add some autoshapes to a worksheet. However I am having a hard time figuring out how to control the location of the autoshape. I tried recording a macro but it is still not making any sense to me. Can somebody help explain how to control the size and location of a autoshape with VBA?

Here is the Code that I am starting with.

Code:
    ActiveSheet.Shapes.AddShape(msoShapeRectangle, 228#, 557.25, 126#, 13.5).Select
    With Selection
        .Characters.Text = "Click Here"
        .ShapeRange.Fill.Visible = msoTrue
        .ShapeRange.Fill.ForeColor.SchemeColor = 43
        .ShapeRange.Line.Visible = msoTrue
        .ShapeRange.Line.ForeColor.SchemeColor = 64
        .ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
        .Name = "Prepared_by_box"
        .OnAction = "eng_design_box"
     End With
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Is this what you mean?

Rich (BB code):
Sub ashape()
    ActiveSheet.Shapes.AddShape(msoShapeRectangle, 228#, 557.25, 126#, 13.5).Select
    With Selection
        .Characters.Text = "Click Here"
        .ShapeRange.Fill.Visible = msoTrue
        .ShapeRange.Fill.ForeColor.SchemeColor = 43
        .ShapeRange.Line.Visible = msoTrue
        .ShapeRange.Line.ForeColor.SchemeColor = 64
        .ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
        .Name = "Prepared_by_box"
        .OnAction = "eng_design_box"
        .Top = Range("C3").Top
        .Left = Range("C3").Left
     End With
End Sub
 
Upvote 0
That worked nicely. Can I control the width by using something like

Rich (BB code):
.Top = Range("C3").Top
.Left = Range("C3").Left
.Bottom = Range("D3").Bottom
.Right = Range("D3").Right
 
Upvote 0

Forum statistics

Threads
1,214,867
Messages
6,122,002
Members
449,059
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top