As the comments say, VBA has automatic garbage collection. That means that when the VBA run time determines an object or variable is no longer used, it may release the object or variable.
In your example, the Scripting.FileSystemObject
object can no longer be accessed once the End With
statement is reached so VBA may release the object there.
Would you have assigned the created object to an object variable, then there are two ways that the object can or will be released. Example:
Sub Example
Dim myObject As Object
Set myObject = CreateObject("Scripting.FileSystemObject")
'
' ...whatever you want to do with it...
'
Set myObject = Nothing ' explicit release of the object
End Sub ' implicit release of the object
The explicit release of the object releases the object by programmer command. That may be usefull of a lot if work still follows where the object is no longer needed as it could decrease the resource demand of the program
The implicit release of the object occurs at the end of the Sub
because the object variable ceases to exist - VBA releases the variable and release its object.