Autoshape type

tpmccarthy

New Member
Joined
Aug 2, 2020
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to make a Comment box with trapezoidal shape. I don't know how to describe/call a shape in the code.Is there a list of shape names to use in a macro?
Any help is appreciated. Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Shapes are named by Excel when they are created. Excel uses default names like Trapezoid 1, Trapezoid 2, ...., Oval 1, .... etc.
Here's a bit of code that allows you to identify all the shapes on the active sheet, and in the case of a trapezoid, it renames it to "MyTrap N". where N is the Nth trapezoid on the sheet.

You can rename any shape by selecting it and then overwriting its name in the box just above the col A header and pressing Enter.
VBA Code:
Sub GetShapeName()
Dim Shp As Shape, Ct As Long
With ActiveSheet
    For Each Shp In .Shapes
        Shp.Select
        MsgBox Shp.Name
        'change the shape name if desired
        If Shp.Name Like "Trapezoid*" Then
            Ct = Ct + 1
            Shp.Name = "MyTrap" & " " & Ct
        End If
    Next Shp
End With
End Sub
 
Upvote 0
welcome to MrExcel

something like this?

VBA Code:
Sub AddTrapezoid()
    Dim shp As Shape, ws As Worksheet
    Set ws = ActiveSheet
    Set shp = ws.Shapes.AddShape(msoShapeTrapezoid, 10, 10, 100, 20)
    shp.Fill.ForeColor.RGB = RGB(0, 0, 255)
    shp.TextFrame.Characters.Text = "yongle wrote this"
    shp.TextFrame.Characters.Font.ColorIndex = 2
    shp.Name = "my comment box"
End Sub
 
Upvote 0
Shapes are named by Excel when they are created. Excel uses default names like Trapezoid 1, Trapezoid 2, ...., Oval 1, .... etc.
Here's a bit of code that allows you to identify all the shapes on the active sheet, and in the case of a trapezoid, it renames it to "MyTrap N". where N is the Nth trapezoid on the sheet.

You can rename any shape by selecting it and then overwriting its name in the box just above the col A header and pressing Enter.
VBA Code:
Sub GetShapeName()
Dim Shp As Shape, Ct As Long
With ActiveSheet
    For Each Shp In .Shapes
       *[B]Shp.Select[/B]
        MsgBox Shp.Name
        'change the shape name if desired
        If Shp.Name Like "Trapezoid*" Then
            Ct = Ct + 1
            Shp.Name = "MyTrap" & " " & Ct
        End If
    Next Shp
End With
End Sub

Thanks JoeMo,
But I can't get the code to run past Shp.Select. it's likely something I'm doing/not doing. I've been "out of the game" (retired) for a number years and I'm stunned by how much I've forgotten. Little help?
 
Upvote 0
welcome to MrExcel

something like this?

VBA Code:
Sub AddTrapezoid()
    Dim shp As Shape, ws As Worksheet
    Set ws = ActiveSheet
    Set shp = ws.Shapes.AddShape(msoShapeTrapezoid, 10, 10, 100, 20)
    shp.Fill.ForeColor.RGB = RGB(0, 0, 255)
    shp.TextFrame.Characters.Text = "yongle wrote this"
    shp.TextFrame.Characters.Font.ColorIndex = 2
    shp.Name = "my comment box"
End Sub


Thanks Yongle
I get you code to run "as is" I can't figure out how to incorporate it into the code I have. (snippet below)
Appreciate any guidance
***********************************
Sub formatComments()

Dim MyComments As Comment
Dim LArea As Long
For Each MyComments In ActiveSheet.Comments
With MyComments
.Shape.AutoShapeType = msoShapeRoundedRectangle
 
Upvote 0
Try this instead

I have added a few other things so that you can see how to alter various properties

VBA Code:
Sub CommentShape()
    Dim MyComments As Comment
    
    For Each MyComments In ActiveSheet.Comments
        With MyComments
            .Shape.AutoShapeType = msoShapeTrapezoid
            .Shape.TextFrame.Characters.Font.Name = "Tahoma"
            .Shape.TextFrame.Characters.Font.Size = 10
            .Shape.TextFrame.Characters.Font.ColorIndex = 2
            .Shape.Line.ForeColor.RGB = RGB(0, 0, 0)
            .Shape.Line.BackColor.RGB = RGB(255, 255, 255)
            .Shape.Fill.Visible = msoTrue
            .Shape.Fill.ForeColor.RGB = RGB(25, 25, 150)
            .Shape.Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
        End With
    Next MyComments
End Sub
 
Upvote 0
Thanks Yongle
This'll be a good tutorial for me . Plus helps with my immediate issue.
I've been retired for quite a while and I'm shocked at what I've forgotten,or never really knew.;)
Thanks again
 
Upvote 0
Thanks JoeMo,
But I can't get the code to run past Shp.Select. it's likely something I'm doing/not doing. I've been "out of the game" (retired) for a number years and I'm stunned by how much I've forgotten. Little help?
Perhaps you are running the code when the active sheet has no shapes on it?? :(
 
Upvote 0
**** embarrassing :sneaky:
Thanks and thanks for not saying what you are probably thinking.;)
Both you guys responding really gives me some stuff to work with!
 
Upvote 0
**** embarrassing :sneaky:
Thanks and thanks for not saying what you are probably thinking.;)
Both you guys responding really gives me some stuff to work with!
You are welcome - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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