Andy
Andy

Reputation: 217

How to change shape color in excel using powershell

I need to automatically import a picture into excel and add a red circle. I am just starting to get the create a shape part but I cannot seem to figure out how to modify it. I have:

$WS = $workbook.worksheets.add()
$WS.select()
$ws.Activate()

$ws.Shapes.AddShape(9, 0, 0, 50, 50)
$circle = $ws.Shapes.AddShape(18, 50, 50, 50, 50)
#$Circle = $ws.Shapes[2]



write-host "fill: " $circle.fill

This adds an oval and a donut, but just outputs "system comobject" and I can't seem to access any of the methods that should be there (like fill/fillform.forecolor). What is the correct way to play with and modify the shape?

Upvotes: 0

Views: 292

Answers (1)

Andrew
Andrew

Reputation: 219

I can't test at the moment but try $circle.ShapeRange.Fill.ForeColor.RGB = RGB(255,0,0). Change the RGB values to your preference.

Upvotes: 1

Related Questions