3

I am beginner in VBA. I have created a Template in Word (.dotm). I have used 30 String object. I don't know whether VBA dispose it or do I need to dispose it manually.

Can anybody please suggest me so I will not have problem of memory in future?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Nanji Mange
  • 2,155
  • 4
  • 29
  • 63
  • 3
    See e.g. [this](http://stackoverflow.com/questions/19038350/when-should-an-excel-vba-variable-be-killed-or-set-to-nothing) answer. – Daniel Dušek Sep 08 '16 at 06:56

1 Answers1

4

No need to dispose. As soon as the string variable is out of scope, the memory is recovered.

'Globally scoped g will be retained until the project is reset with `End`
Public g as string

Sub foo()
  Dim s as string
  s = "foo"

  g = "bar"

's is destroyed on exiting the sub
End Sub

Sub bar()
  ' Reset the project will reclaim all variables including Globals
  End
End Sub
ThunderFrame
  • 9,352
  • 2
  • 29
  • 60