使用MS Access 365 VBA设置Excel条件格式时报错:无效过程调用或参数
问题排查与修正方案
你的VBA代码出现"无效的过程调用或参数"错误,是两个细节问题导致的:
多余的Operator参数
当条件格式类型为xlExpression时,不需要指定Operator参数(该参数仅适用于单元格值直接比较的场景),第一个条件格式里的Operator:=xlEqual属于冗余参数,会触发参数错误。公式语法错误
第二个条件格式的Formula1中,OR函数缺少一个闭合的右括号,完整的公式应该是=OR(ISBLANK($L2),$L2<>'Yes'),括号不匹配会导致公式无效,进而引发错误。
修正后的代码如下:
Set lrngReport = .Range("$A$2:$" & lstrLastCol & "$" & lintLastRow) With lrngReport .FormatConditions.Delete 'Condition where no record in Donor Comments Modified .FormatConditions.Add Type:=xlExpression, Formula1:="=OR(ISBLANK($J2),$J2<>'Yes')" With .FormatConditions(1) .Interior.Color = RGB(255, 243, 109) .Font.Bold = True .StopIfTrue = False End With 'Not reviewed condition .FormatConditions.Add Type:=xlExpression, Formula1:="=OR(ISBLANK($L2),$L2<>'Yes')" With .FormatConditions(2) .Font.Color = RGB(225, 6, 0) .Font.Bold = True .StopIfTrue = False End With End With
内容的提问来源于stack exchange,提问作者Stephen Levine
相关产品推荐
相关产品推荐

