AHK Excel COM - 在 sheet 内更改颜色

AHK Excel COM - Change color within a sheet

Whosebug 成员您好,

我有一个 Excel 工作表,其中特定单元格具有红色边框和红色字体大小。 目前,我正在寻找一种用另一种颜色代替红色的方法,例如蓝色.

由于我没有任何 VBA 知识,我试图通过 AutoHotkey 及其 COM 支持来实现这一点。 我取得了一些进步! 但是,即使它有效,它也不会更改多个单元格的边框。 字体颜色也一样 - 有些会改变,有些不会改变。

这是我的代码:

    F1::
xl := ComObjActive("Excel.Application") ; Connect to Excel
ws := xl.ActiveSheet ; Connect to worksheet
column = 65 ; ASCCI code
Loop, 800
{
  r++ ; row 1
  if (r = 41) ; If row 41 was reached:
  {
    r = 1 ; Go back to row 1
    column := column + 1 ; Next column
  }
  c := Chr(column) ; ASCCI to String
  cell = %c%%r% ; Cell = e.g. A1, etc.
  ;if xl.range(cell).Borders(xlEdgeLeft).Color = 0x0000FF ; If border color is red - TYPE CONFLICT!
  if xl.range(cell).Borders.Color = 0x0000FF ; If border color is red: - WORKS PARTLY
  {
    ;xl.range(cell).Borders(xlEdgeLeft).Color := 0xFFD700 ; Set blue color - I DOUBT IT WILL WORK!
    xl.range(cell).Borders.Color := 0xFFD700 ; Set to blue - WORKS PARTLY
  }
  if xl.range(cell).Font.Color = 0x0000FF ; If font color is red:  - WORKS PARTLY
  {
    xl.range(cell).Font.Color := 0xFFD700 ; Set to blue - WORKS PARTLY
  }
}
return

如您所见,我已经尝试过 if xl.range(cell).Borders(xlEdgeLeft).Color = 0x0000FF 这似乎不起作用。 它说,"TYPE CONFLICT".

在此屏幕截图中,您可以看到所有成功的颜色调整(蓝色)。 其余部分为红色,未更改。 Result

任何帮助将不胜感激!

问题已解决。

for xlCell in xl.ActiveSheet.UsedRange.Cells ; Used cells
{
  for xlBorder in xlCell.Borders ; Where borders are used
  {
    if (xlBorder.Color = 0x0000FF) ; Red
    {
      xlBorder.Color := 0x5FD200 ; Green
    }
    if (xlCell.Font.Color = 0x0000FF) ; Red
    {
      xlCell.Font.Color := 0x5FD200 ; Green
    }
  } 
}
for xlShape in xl.ActiveSheet.Shapes ; Used shapes
{
  if (xlShape.Line.ForeColor.RGB = 0x0000FF) ; Red
  {
    xlShape.Line.ForeColor.RGB := 0x5FD200 ; Green
  }
}

谢谢。

P.S。对于文本中的字体颜色,没有解决方案。