Introduction
In this article, I will share how to change the outline (border) color of a shape using VBA.
I previously learned how to change the fill color, but I also wanted to customize the line color to suit my design. Here is the method I found.
Conclusion: Use “.Line.ForeColor.RGB”
You can specify the outline color using the property .Line.ForeColor.RGB.
Sample Code:
ActiveSheet.Shapes(1).Line.ForeColor.RGB = RGB(255, 255, 255)
This code sets the outline color of the first shape on the active sheet to White.
Note:
RGB(255, 255, 255)represents White.- If you want to set it to Black, use
RGB(0, 0, 0).
Common RGB Color Codes
Here is a list of common colors and their RGB values for your reference.
| Color Name | RGB Code |
| Black | RGB(0, 0, 0) |
| White | RGB(255, 255, 255) |
| Red | RGB(255, 0, 0) |
| Green | RGB(0, 255, 0) |
| Blue | RGB(0, 0, 255) |
| Gray | RGB(128, 128, 128) |
Specifying a Shape by Name
If you have multiple shapes on a sheet, it is safer to specify the target shape by its name rather than its index number.
' Example: Changing the outline of a shape named "Rectangle 1" to Black
ActiveSheet.Shapes("Rectangle 1").Line.ForeColor.RGB = RGB(0, 0, 0)
Summary
- To change the outline color, use
Shape.Line.ForeColor.RGB = RGB(Red, Green, Blue). - Remember that
RGB(255, 255, 255)is White andRGB(0, 0, 0)is Black. - You can access shapes by their index number (e.g.,
Shapes(1)) or by their name (e.g.,Shapes("Name")).
Through this exercise, I deepened my understanding of basic shape manipulation in VBA. Next, I plan to explore how to change the weight (thickness) and style (dashed lines, etc.) of the borders.
