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
  • 963,270
  • 265
  • 3,804
  • 3,187
Nanji Mange
  • 1,955
  • 3
  • 26
  • 52
  • 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,091
  • 2
  • 26
  • 57