我有一个基于条件格式化单元格的宏。 这里是代码:从c#打开文件时Excel宏没有正确执行#
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”值的单元格都是红色的。大!但是,当我运行我的应用程序打开文件,进行更改并保存它时,一些“OK”单元格是“红色”(太棒了!),但其他是“绿色”(坏!)。
有没有人有想法?
谢谢