[英]VBA runs on Windows Excel but not in Mac Excel
when I run a VBA on windows excel, it works.当我在 windows excel 上运行 VBA 时,它可以工作。 When I run the same vba on excel for Mac, it doesn't work.
当我在 excel for Mac 上运行相同的 vba 时,它不起作用。 Then I click "debug" it highlits the following part of the macro
然后我单击“调试”它会突出显示宏的以下部分
Selection.Replace What:="-", replacement:="/", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
THe SearchFormat
parameter is not available on Excel for Mac: SearchFormat
参数在 Excel for Mac 上不可用:
You can remove SearchFormat
and ReplaceFormat
if they're not necessary, otherwise if they are necessary then use compiler directive such as :如果不需要,您可以删除
SearchFormat
和ReplaceFormat
,否则如果需要,则使用 编译器指令,例如:
#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
This will still use the SearchFormat
and ReplaceFormat
on Windows OS (but not on Mac OS -- in that case you'd need to use some additional logic) and it will not raise a runtime error on the Mac OS.这仍将在 Windows 操作系统上使用
SearchFormat
和ReplaceFormat
(但不在 Mac OS 上——在这种情况下,您需要使用一些额外的逻辑)并且它不会在 Mac OS 上引发运行时错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.