Pallav Raj
Pallav Raj

Reputation: 1744

code is behaving differently on other system

This is my L.O.C which is working differently on other system. This code is written in VBA Excel and performing search operation on PowerPoint file.

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

Here, if the word which is in searchtext is not present in PowerPoint file, then it returns "Nothing" in my system but similarly it returns blank("") in my colleague's system. And one thing more, oTmpRng = nothing is being return in my system, in this case the below line of code should not execute. But still it goes inside it.

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

Note : Both system consists of Office 2007. Can anyone make me know why this is happening.

Upvotes: 2

Views: 129

Answers (1)

Jimmy Smith
Jimmy Smith

Reputation: 2451

Do you have on error resume next in the code somewhere? That may cause that to always execute if there's an error in the condition.

Otherwise, Not has the lowest precedence, so I always use parentheses, Something to try:

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

or

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

Upvotes: 1

Related Questions