当我在Windows excel上运行VBA时,它可以工作。当我在Mac上运行excel上的相同vba时,它不起作用。然后我点击" debug"它突出了宏的以下部分
Selection.Replace What:="-", replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
答案 0 :(得分:1)
Excel for Mac上没有SearchFormat
参数:
如果没有必要,您可以删除SearchFormat
和ReplaceFormat
,否则如果有必要,请使用compiler directive such as:
#IF MAC THEN
Selection.Replace What:="-", replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
#ELSE
Selection.Replace What:="-", replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
#END IF
这仍然会在Windows操作系统上使用SearchFormat
和ReplaceFormat
(但不能在Mac OS上使用 - 在这种情况下,您需要使用一些额外的逻辑)并且不会引发运行时Mac OS上出错。