title: Global variable resets when adding a command button with code
body: <p>I have this short piece of code</p>
  
  <pre><code>Public n As Integer
  
  Public Sub Foo()
  
      For i = 0 To 4
  
          MyModule.n = MyModule.n + 1
  
      Next i
  
  End Sub
  </code></pre>
  
  <p>which is defined in a Module named <code>MyModule</code>. This code is working as expected: After executing for the first time 'MyModule.n' has the value 5. After executing the second time it has the value 10 and so on.</p>
  
  <p>When I extend the code, to add a CommandButton and place it onto the working sheet, the global variable <code>MyModule.n</code> loses it's value on every new call of <code>Foo</code>:</p>
  
  <pre><code>Public n As Integer
  
  Public Sub Foo()
  
      Dim btn As OLEObject
  
      For i = 0 To 4
  
          Set btn = Worksheets("Aufträge").OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
          Left:=122, Top:=321, Width:=30, Height:=30)
  
          MyModule.n = MyModule.n + 1
  
      Next i
  
  End Sub
  </code></pre>
  
  <p>The code seems to work because the command button is created and placed correctly. Why does the global variable reset if executing the second code fragment?</p>
  
  <p>Furthermore I can't place a break point after or inside the For-Loop in the second code fragment. I get the message <code>Can't enter break mode at this time</code>.</p>