VBA在Windows Excel上运行,但在Mac Excel中不运行

时间:2016-09-23 13:18:22

标签: excel macos vba excel-vba

当我在Windows excel上运行VBA时,它可以工作。当我在Mac上运行excel上的相同vba时,它不起作用。然后我点击" debug"它突出了宏的以下部分

Selection.Replace What:="-", replacement:="/", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

1 个答案:

答案 0 :(得分:1)

Excel for Mac上没有SearchFormat参数:

如果没有必要,您可以删除SearchFormatReplaceFormat,否则如果有必要,请使用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操作系统上使用SearchFormatReplaceFormat(但不能在Mac OS上使用 - 在这种情况下,您需要使用一些额外的逻辑)并且不会引发运行时Mac OS上出错。