2014-05-05 27 views
2

這是我的L.O.C,它在其他系統上的工作方式不同。此代碼是使用VBA Excel編寫的,並在PowerPoint文件上執行搜索操作。代碼在其他系統上的行爲不同

Set oTmpRng = oTxtRng.Find(_ 
    FindWhat:=searchtext, _ 
    WholeWords:=False, _ 
    matchcase:=matchvalue) 

在這裏,如果這是在SEARCHTEXT的詞不存在於PowerPoint文件,然後返回在我的系統「沒什麼」,但同樣它返回空(「」)在我同事的系統。還有一件事,oTmpRng =我的系統中沒有任何東西被返回,在這種情況下,下面的代碼行不應該執行。但它仍然在裏面。

If Not oTmpRng Is Nothing and oTmpRng <> "" Then 
    msg "It should not execute" '<- This line should not execute when oTmpRng=Nothing 
End If 

提示:這兩種系統由Office 2007的 的任何人都可以讓我知道爲什麼發生這種情況。

回答

1

您是否在代碼的某處出現錯誤繼續的下一個代碼?這可能會導致在條件中存在錯誤時始終執行該操作。

否則,不具有優先級最低,所以我總是用括號, 一些嘗試:

If (Not oTmpRng Is Nothing) and oTmpRng <> "" Then 
    msg "It should not execute" '<- This line should not execute when oTmpRng=Nothing 
End If 

If Not (oTmpRng Is Nothing and oTmpRng = "") Then 
     msg "It should not execute" '<- This line should not execute when oTmpRng=Nothing 
    End If 
+0

哇!格雷特......非常感謝。我感到非常高興:-)。有效。 – Brain

相關問題