【发布时间】:2015-02-24 03:24:56
【问题描述】:
我有一个宏,可以根据条件格式化单元格。 这是代码:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Set MyPlage = Sheets("Report").Range("E13:E1500")
For Each Cell In MyPlage
If Cell.Value = "L" Then
Cell.Borders.ColorIndex = 1
Cell.Font.ColorIndex = 3
ElseIf Cell.Value = "K" Then
Cell.Borders.ColorIndex = 1
Cell.Font.ColorIndex = 44
ElseIf Cell.Value = "J" Then
Cell.Borders.ColorIndex = 1
Cell.Font.ColorIndex = 10
ElseIf Cell.Value = "ü" Then
Cell.Borders.ColorIndex = 1
ElseIf Cell.Value = "" And Cell.Offset(0, 1).Value <> "" Then
Cell.Borders.ColorIndex = 1
Else
Cell.Borders.ColorIndex = 2
End If
Next
宏在保存工作簿之前执行。 它在 excel 中完美运行。
我的问题是我有一个 C# 应用程序可以打开这个 excel 文件并用数据更新它。
当我保存文件(从代码)并打开文件(从桌面或任何地方)时,我看到宏已运行,但某些单元格的颜色(格式)不正确。
例如,如果单元格值为“OK”,则单元格的宏格式应为“红色”。 当我从 Excel 中保存工作簿时,所有具有“OK”值的单元格都是红色的。太好了!
但是当我运行打开文件、进行更改并保存它的应用程序时,一些“正常”单元格是“红色”(很好!),而其他是“绿色”(糟糕!)。
有人有想法吗?
谢谢
【问题讨论】: