1

I am trying to change the color of all the arrows in a document to red. However, they keep changing to blue.

I tried this:

$shapes = $doc.Shapes
foreach ($shape in $doc.Shapes) {
    if($shape.Name -like "Straight Arrow Connector*"){
        $red = [System.Drawing.Color]::FromArgb(255,255,0,0)
        $shape.Line.ForeColor.RGB = $red.ToArgb()
    }
}

From the comment below, this ended up fixing my issue:

$shapes = $doc.Shapes
$color = [System.Drawing.Color]::Red
$red = $color.R + 0x100 * $color.G + 0x10000 * $color.B
foreach ($shape in $doc.Shapes) {
        if($shape.Name -like "Straight Arrow Connector*"){
              $shape.Line.ForeColor.RGB = $red
        }
}
ScareFries
  • 53
  • 5
  • 2
    ```ForeColor.RGB``` expects an Office/VBA-style ```RGB(r, g, b)``` integer value (16777215 for red) - see https://learn.microsoft.com/en-us/office/vba/api/word.colorformat.rgb, but ```ToArgb``` gives you a dotnet ARGB integer value (-65536 for red) - see https://learn.microsoft.com/en-us/dotnet/api/system.drawing.color.toargb?view=net-6.0. Try ```$red = [Microsoft.VisualBasic.Information]::RGB(255, 0, 0)```... or see https://stackoverflow.com/a/36990877/3156906 – mclayton Jan 27 '23 at 00:31
  • 1
    you should really post the solution to the problem in the answer section, you can [self-answer](https://stackoverflow.com/help/self-answer). It will help future readers find your question and its proper answer to the problem – Santiago Squarzon Jan 28 '23 at 14:49

0 Answers0