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

当我在Windows Excel上运行VBA时,它工作。 当我在Mac上运行相同的VBA,它不起作用。 然后,我点击“debugging”它macros观macros的下面的部分

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

SearchFormat参数在Mac版Excel上不可用:

如果不需要,可以删除SearchFormatReplaceFormat ;否则,如果需要的话,使用编译器指令,例如 :

 #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上产生运行时错误。