Try running some debugging before this to determine where the issue lies. So let's try something like this, for instance:
<font class="small">Code:</font><hr /><pre>
'Check that the parent isn't the problem
'Set up a debug object
Set dbg1 = w1.Find(EnterUniqueProperty, PropValue, Depth)
Set w2 = w1.SWTObject("Composite", "*", 4).SWTObject("Composite", "").SWTObject("Tree", "")
The above might not be exactly what you need, but it should be a start. The key is to consistently find the object, not that you want to find, necessarily, but the object that you are expecting to find when you define w2. This way you can go back to your previous runs and see exactly what got logged as the name for that object.
This is why Find is so powerful. In fact, I have an extremely accurate find routine which I use in the framework on the automation project at my shop. I almost never define objects at a script level. Try and see if you are able to find it using the Find method. If you can, then you will be able to see where the differences in the object name are and either continue to use the Find method instead of defining in your script, or adjust your script to account for whatever is changing.
Ooops, one last thing. I just added the Process.Refresh() Method to the Beginning of the code snippet. Process would be your process name (so like p1 maybe). Refresh() will refresh the process tree in the event that it hasn't been updated properly before you set your object.
In addition to Brent's use of the Find method, you might want to include some "Wait" calls as well. If you're clicking on an object like a button or something, there may be a delay during which the object you are expecting to come up next is not immediately available.