The problem is that you're asking for the selected item in the tree before the user has selected anything. As a result, the "Selected Item" property is generating a null reference, which won't give you any valid properties or methods.
I figured out was wrong by right-clicking on the error cluster and choosing "Explain Error" to get more info about code 97; the explanation mentioned a null reference.
What you need to do is filter out any 97 errors at the "Get Selected Tree Item" level. Then your loop executes without error when nothing is selected and returns the desired result when an item is selected. Attached is an example of such a modification.
Hope it helps,
John Lum
National Instruments