2

is the fact of liberating an instance of a worksheet at the end of a procedure useful for something? here's the code:

sub Macro(path as String)

  Dim ws as worksheet
  set ws = thisWorkbook.Sheets("Recap")
  ....
  ...'do actions on the sheet ws
  ...
  set ws = Nothing

end Sub

so my question is: if I do not release the object ws, is that it will automatically release? Set ws = Nothing serves some at the end of the procedure?

thanks

Benss
  • 305
  • 2
  • 3
  • 11
  • 4
    If you remember music spinning at 33¹⁄₃ rpm, phones that had cords and a VBA that leaked memory like a sieve then set the object to *Nothing* before exiting the sub for peace of mind. If the only cord attached to your phone was for the pre-bluetooth earbuds then you probably shouldn't need it. –  May 10 '15 at 19:06
  • @Jeeped that has to be the best answer to this question I've ever seen. Literally in stitches! – SierraOscar May 10 '15 at 20:15
  • I think its good practice when you're working with the windows API or COM but generally the VBA garbage collector has you covered. – Coder375 May 11 '15 at 08:40
  • If working with Windows API things stay open until the program exits unless the programmer calls `CloseHandle` or similar. –  May 12 '15 at 01:28

1 Answers1

1

No. It is set to nothing on end sub / end function.

See http://blogs.msdn.com/b/ericlippert/archive/2004/04/28/122259.aspx