以下代码片段在英文版 Excel 中运行正常,但是当尝试在葡萄牙语版 Excel 中的同一工作簿中运行此代码时,它会出错。
' Add color bars on every other row - attempt to make list
' easier to read.
' "PlaceAt" is a worksheet range passed into the function
With Range(PlaceAt.offset(1, 0), PlaceAt.offset(i + 1, 7))
.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)=1"
.FormatConditions(1).Interior.ColorIndex = 20
End With
我认为问题在于,在葡萄牙语中,ROW 函数拼写为 LIN(不确定 MOD 函数会是什么)并且由于该函数是使用 vba 插入的,Excel 的翻译功能没有机会翻译打开文档时通常使用的函数名称。
有什么想法吗?
最佳答案
是的FormatConditions公式必须使用本地格式。
我的解决方法是将所需的公式写入一个单元格,然后获取该单元格的 FormulaLocal,它应该是您所用语言的准确翻译:
Dim tmpCell As Range
Set tmpCell = Range("IV1")
tmpCell.Formula = "=mod(row(),2)=0"
.FormatConditions.Add(xlExpression, Formula1:=tmpCell.FormulaLocal)
不知道是否有更清洁的解决方案,但如果有的话,我想知道,所以请分享...
关于vba - 在外语版本的 Excel 中从 vba 调用工作表函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16948250/