How to draw wedge shape with outline in Excel VBA

0 votes

Using VBA in Excel, I want to create a wedge-shaped section of a circle (the desktop version from Office 365 ProPlus). The code below gives me the correct shape, but the curved section is merely an outline:

Dim myArc as Shape
Set myArc = ActiveSheet.Shapes.AddShape(msoShapeArc, 200, 100, 100, 100)
With myArc
.Adjustments(1) = 0
.Adjustments(2) = 45
.Fill.Visible = msoTrue
End With

Only the curve has an outline; the straight edges are undecorated. How can I completely encircle the shape using an outline? Should I substitute msoShapeArc with another shape? I've tried using the code below to change the line's colour, weight, and visibility, but it only modifies the curved edge, not the straight edges.

With myArc
.Line.ForeColor.RGB = RGB(0, 0, 0)
.Line.Weight = 1
.Line.Visible = msoTrue
End With

I've been able to find documentation on general shape properties, but not which properties apply to which type of shape, and how they actually work to control its appearance.

Dec 25, 2022 in Others by Kithuzzz
• 28,900 points
55 views

1 answer to this question.

0 votes

According to https://learn.microsoft.com/en-us/office/vba/api/excel.adjustments:

Because each adjustable shape has a different set of adjustments, the best way to verify the adjustment behavior for a specific shape is to manually create an instance of the shape, make adjustments with the macro recorder turned on, and then examine the recorded code.

This worked for me to create a pie wedge:

Sub WedgeTest()
    Dim ws As Worksheet, shp As Shape
    Set ws = ActiveSheet
    
    Set shp = ws.Shapes.AddShape(msoShapePie, 50, 50, 100, 100)
    With shp
        .Adjustments.Item(1) = -90 'degrees from 3 oclock
        .Adjustments.Item(2) = -45 'degrees from 3 oclock
        .Fill.Visible = msoFalse
        With .Line
            .Visible = msoTrue
            .ForeColor.RGB = RGB(255, 0, 0)
            .Transparency = 0
        End With
    End With
End Sub
answered Dec 25, 2022 by narikkadan
• 53,520 points

Related Questions In Others

0 votes
1 answer

How to create a drop-down in excel with custom values

You can accomplish that using code rather ...READ MORE

answered Sep 25, 2022 in Others by narikkadan
• 53,520 points
150 views
0 votes
1 answer

How to merge two cells in excel with same field name

Insert 2 new columns, G & H. Enter ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 53,520 points
172 views
+1 vote
1 answer

How to use VBA in Excel for Google Search?

Try this: Private Const LicenseRegistration As String = ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 53,520 points
351 views
0 votes
1 answer

How to Freeze Top Row and Apply Filter in Excel Automation with C#

Try this: // Fix first row workSheet.Activate(); workSheet.Application.ActiveWindow.SplitRow = 1; workSheet.Application.ActiveWindow.FreezePanes ...READ MORE

answered Oct 22, 2022 in Others by narikkadan
• 53,520 points
343 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
533 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
2,415 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 22,960 points
117 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,630 points
300 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 53,520 points
242 views
0 votes
1 answer

Excel-VBA - How to identify Target range (more than 1 cell) is deleted in a Worksheet_Change function?

You misunderstand the purpose of the function ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 53,520 points
1,188 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP