title: VBA (Excel) ActiveX ListBox Change Event recursive behaviour
body: <p>I'm not a VBA programmer so I apologize in advance if some of my terminology in this question is incorrect. A colleague of mine wanted to clear the selection from a list box as soon as it was selected. After some googling we found one way to do it was via the Change event. Initially we tried:</p>
  
  <pre><code>Private Sub ListBox1_Change()
      For i = 0 To ListBox1.ListCount - 1
          ListBox1.Selected(i) = False
      Next i
  End Sub
  </code></pre>
  
  <p>However, it seemed that setting the <strong>Selected</strong> property to False triggers a <strong>Change</strong> event on the list box and this effectively becomes an infinite loop and causes Excel (2007) to crash. Given we knew there were two entries we also tried:</p>
  
  <pre><code>Private Sub ListBox1_Change()
      ListBox1.Selected(0) = False
      ListBox1.Selected(1) = False
  End Sub
  </code></pre>
  
  <p>And that works! Though we'd expect the same behaviour - for the setting of the <strong>Selected</strong> property to cause the Change event to trigger again and to get an infinite loop. </p>
  
  <p>However it seems that once e.g. <strong>ListBox1.Selected(0) = False</strong> the Change event is re-triggered but in that iteration it doesn't retrigger on this line - i guess because it knows that this <strong>Selected</strong> property has already been set to to <strong>False</strong> for this item, so nothing is changing.</p>
  
  <p>But if that is the case then we'd also expect that behaviour in the <strong>first</strong> solution .. so it seems there is some difference in saying <strong>ListBox1.Selected(i) = False</strong> versus specifying the actual item index directly (rather than via the variable <strong>i</strong>).</p>
  
  <p>Does anyone know the reason for this behaviour? Hope the question makes sense i've tried to explain it as best I can.</p>
  
  <p>Thanks
    Amit</p>