Insert the Shape

  • In this web page i explained how to add a shape in a worksheet by using VBA Macros
  •  

  • Click on below mentioned image to watch the video:
  • Download The Workbook

     

    Sub Insert_And_Format_The_Button_Shape_In_Excel_By_Using_VBA_Macros()

    'Restrict the Number of Worksheets in Newly created workbook
    Application.SheetsInNewWorkbook = 2

    'Define the Object Varible for workbook object
    Dim Wkb As Workbook

    'Add the New workbook
    Set Wkb = Workbooks.Add

    'Define the Object variable for worksheet Object
    Dim Sh As Worksheet

    'Allocating the sheet to the Object variable
    Set Sh = Wkb.Sheets("Sheet2")

    'Activate the sheet
    Sh.Activate

    'Define the Range to add the Rectangular shape
    With Sh.Range("L5:Q6")

    'Define the variable for shape
    Dim Shp As Shape

    'Add the Shape
    Set Shp = Sh.Shapes.AddShape(Type:=msoShapeRectangle, _
    Left:=.Left, _
    Top:=.Top, _
    Width:=.Width, _
    Height:=.Height)
    End With

    'Format the shape
    With Shp.TextFrame2
    .TextRange.Characters.Text = "Run The Macro"
    .TextRange.Font.Size = 20
    .VerticalAnchor = msoAnchorMiddle
    .HorizontalAnchor = msoAnchorCenter
    .TextRange.Font.Name = "Adobe Heiti Std R"
    .TextRange.Font.Fill.Visible = msoTrue
    .TextRange.Font.Fill.ForeColor.RGB = RGB(255, 255, 255)
    End With
    Shp.Fill.ForeColor.RGB = RGB(192, 0, 0)

    Application.SheetsInNewWorkbook = 3
    End Sub