can we draw shape?

bhandari

Active Member
Joined
Oct 17, 2017
Messages
359
my intention to draw shape by using cell reference
i like to give shape dimensions,angles which i want to draw triangle rectangle...etc in excel
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Here is a sample:
Not sure what type shape you want.
Will add shape to active cell.

I showed you two different shapes. Remove ' from in front of line of code to get that line of code to work.

If you want another type shape run the macro recorder pick the shape you want and then look at the code and modify this script to suit your needs.

Code:
Sub Add_Shape()
Dim Left  As Long
Dim Top As Long
Dim Width As Long
Dim Height As Long
Left = ActiveCell.Left
Top = ActiveCell.Top
Width = Selection.Width
Height = ActiveCell.Height
ActiveSheet.Shapes.AddShape(msoShapeRectangle, Left, Top, Width, Height).Select
'ActiveSheet.Shapes.AddShape(msoShapeIsoscelesTriangle, Left, Top, Width, Height).Select
With Selection.ShapeRange.Line
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 0, 0) 'Set Box color to red. Modify if you want
        .Transparency = 0
        .Weight = 4.5 'Set thickness of Box change thickness if you want
    End With
    
    'Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Fill.ForeColor.RGB = RGB(0, 0, 255)
End Sub
 
Upvote 0
can we use edit points for shapes
if i right click on shape,i see "edit point" option to edit the shape
can we do it with macro
 
Upvote 0
I see what you mean.

From my use of the Macro Recorder it appears those edit points are not recorded.
So I would not know if some how you can write code to make those edit points.
You could make the shape the way you want and then hide or show the shape like this:


Give your shape a new name if you like or use the default name then use a script like this:
This toggles the shape from visible to not visible.

Code:
Sub Hide_Shape()
ActiveSheet.Shapes.Range("My_Shape").Visible = Not ActiveSheet.Shapes.Range("My_Shape").Visible
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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