Excel 代码在其他系统上的行为不同

Excel 代码在其他系统上的行为不同,excel,vba,Excel,Vba,这是我的信用证,它在其他系统上的工作方式不同。此代码用VBA Excel编写,并对PowerPoint文件执行搜索操作 Set oTmpRng = oTxtRng.Find( _ FindWhat:=searchtext, _ WholeWords:=False, _ matchcase:=matchvalue) 在这里,如果searchtext中的单词在PowerPoint文件中不存在,那么它在我的系统中返回“Nothing”,但在我同事的系统中同样返回空白(“”)。

这是我的信用证,它在其他系统上的工作方式不同。此代码用VBA Excel编写,并对PowerPoint文件执行搜索操作

Set oTmpRng = oTxtRng.Find( _
    FindWhat:=searchtext, _
    WholeWords:=False, _
    matchcase:=matchvalue)
在这里,如果searchtext中的单词在PowerPoint文件中不存在,那么它在我的系统中返回“Nothing”,但在我同事的系统中同样返回空白(“”)。还有一件事,oTmpRng=在我的系统中没有返回任何内容,在这种情况下,下面的代码行不应该执行。但它还是在里面

If Not oTmpRng Is Nothing and oTmpRng <> "" Then
     msg "It should not execute" '<- This line should not execute when oTmpRng=Nothing
End If
如果不是oTmpRng为Nothing且oTmpRng为“”,则

msg“It should not execute”您是否在代码的某个地方有错误恢复?这可能会导致在条件中出现错误时始终执行

否则,Not的优先级最低,所以我总是使用括号, 尝试一下:

If (Not oTmpRng Is Nothing) and oTmpRng <> "" Then
     msg "It should not execute" '<- This line should not execute when oTmpRng=Nothing
End If
如果(非oTmpRng为空)和oTmpRng“”,则

msg“它不应该执行”'哇!!磨碎非常感谢你。我感到非常高兴:-)。成功了。
If Not (oTmpRng Is Nothing and oTmpRng = "") Then
         msg "It should not execute" '<- This line should not execute when oTmpRng=Nothing
    End If