Microsoft Word ShapesColor Formatting Code Example

Microsoft Word ShapesColor Formatting Code Example

Fill

Is an object which offers various properties and methods to perform color formatting of a shape. ShapesColor uses Fill object exposed by Shape object hence mostly properties of Fill object used to format inner or outer properties of a shape. Consider below shape which we will manipulate using VBA (Visual Basic for Applications) code.

Example source

Code example

Public Sub ColorFormattingExample()
    
    'declare variable to grab shape object
    Dim oCircle As Shape
    
    'Bind shape reference
    Set oCircle = ActiveDocument.Shapes(1)
    
    'Format back color
    oCircle.Fill.BackColor = vbGreen
    
    'Format fore color
    oCircle.Fill.ForeColor = vbRed
    
    'format two color gradient
    oCircle.Fill.TwoColorGradient msoGradientVertical, 1
    
    'Memory cleanup
    Set oCircle = Nothing
End Sub

Output

Please leave your comments or queries under comment section also please do subscribe to our blogs to keep your self upto date.

Leave a Reply

Your email address will not be published. Required fields are marked *