VBA add a circle
0. Quick guide - add a circle to a WS
In this module:
- VBA code - to add a circle element to a worksheet (WS) as an msoShapeOval object (available from the Insert > Illustrations > Shapes > Basic Shapes > Oval menu sequence). The circle concept could be included in a WS dashboard interface
1. WS circle
The demonstration circle is shown in figure 1. It has top left cell anchor B5, and element width and height of 180 points.
2. VBA code for WS circle
Code 1 uses the Shapes.AddShape method with parameters by name.
Code 1: Sub
xlfAddCircle1
procedure adds a circle element to the WS (see figure 1)
Option Explicit Const topleft As String = "C5" ' anchor cell Const diam As Integer = 180 ' points ' =========================== Sub xlfAddCircle1() Dim Shp As Shape Dim TLCleft As Double Dim TLCtop As Double TLCleft = Range(topleft).Left TLCtop = Range(topleft).Top Set Shp = ActiveSheet.Shapes.AddShape(Type:=msoShapeOval, _ Left:=TLCleft, Top:=TLCtop, _ Width:=diam, Height:=diam) With Shp .Fill.Visible = msoFalse .Line.Weight = 10 .Line.ForeColor.Brightness = 0.4 .ThreeD.BevelTopType = msoBevelCircle End With End Sub
References
- excelatfinance.com MsoShapeType enumeration, accessed 29 January 2019
- Microsoft (2017) Shape object (Excel), accessed 29 January 2019
- Download the Excel file for this module: xlf-add-circle-1.xlsm [15 KB]
- Development platform: Office 365 ProPlus Excel 64 bit.
- Published: 29th January 2019
- Revised: Friday 24th of February 2023 - 03:12 PM, Pacific Time (PT)