AHK Excel COM-更改工作表中的颜色

时间:2018-10-01 14:34:55

标签: excel com autohotkey

你好stackoverflow成员,

我有一个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

如您所见,如果xl.range(cell).Borders(xlEdgeLeft).Color = 0x0000FF,我已经尝试过 这似乎不起作用。 上面写着“ TYPE CONFLICT”。

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

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

问题解决了。

[{id: 0, name: example1}, {id: 1, name: example2}, {id: 2, name: example3}]

还是谢谢。

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