All object references must be deleted when they are no longer required, to release the memory they were using.
You delete an OLE Automation reference to the object variable in CitectVBA using the CitectVBA Nothing keyword within a CitectVBA Set statement in the following syntax:
Set <objVarName> = Nothing
where:
Set
is the required reference
assignment/release statement keyword.<objVarName>
represents the required name
of the variable holding the reference.Nothing
is the keyword used to release the
object reference.When several object variables refer to the same object, they also refer to the memory and system resources associated with the object. These resources are released only after all of them have been set to Nothing, either explicitly using Set, or implicitly after the last object variable set to Nothing goes out of scope.
Example
' Word example
' create variable to store object reference
Dim objWord as Object
' create object and assign reference to variable
Set objWord = CreateObject( "Word.Document" )
' insert appropriate VBA code here to manipulate Word object
' release reference
Set objWord = Nothing
' Excel example
' create local variables
Dim objExcelApp As Object
Dim objExcelCht As Object
' create the app object and assign the reference
Set objExcelApp = CreateObject("Excel.Application")
' create a chart and assign the reference
Set objExcelCht = objExcelApp.Charts.Add()
' insert appropriate VBA code here to manipulate Excel objects
' delete the objects
Set objExcelApp = Nothing
Set objExcelCht = Nothing
See Also