title: Should I reset a VBA object variable or close the set object then set to a new variable?
body: <p>For a VBA program that uses a single object variable multiple times, is it best to reset the variable in the loop without first setting the variable to nothing (which can be done at the end outside of the loop), or should the variable always be set to nothing after each instance of use. From a reference counting perspective it seems best to set to nothing as I never have need for the previous state of the object once it has been changed to the next variable (I'm not sure how one would retrieve the previous state but I gather that there must be a function of such from this <a href="https://stackoverflow.com/questions/41990017/is-a-vba-object-destroyed-when-the-variable-is-set-to-a-new-object">question</a>). Another relevant question that I examined can be found <a href="https://stackoverflow.com/questions/11395180/vba-reference-counting-object-destruction?rq=1">here</a>.</p>
  
  <p>The application which triggered this question is one where I cycle through many Word documents, pulling relevant information from each of them. See example below:</p>
  
  <pre><code>dim objDoc as object, objWord as object
  Set objWord = CreateObject("Word.Application")
  for r=2 to 40
      'Some code to set filename 
      Set objDoc = objWord.Documents.Open(filename, ReadOnly:=False, Visible:=False)
      'Code to retrieve relevant info from document
      objDoc.close
      Set objDoc = nothing 'Should this go here?
  next r
  set objDoc = nothing 'Or should it go here?
  objWord.Quit
  </code></pre>
  
  <p><strong>The Question</strong>: Does it matter when you set  an object variable to nothing in terms of code efficiency or problem avoidance. I have highlighted above two options for where I believe that should go with the third option being that it doesn't matter when I set the variable to nothing</p>