I have read countless times that you should always release objects at the end of your projects, such as:
Sub Test()
Dim obj As Object
Set obj = GetObject(, "xxxxxx.Application")
' Code your project...
Set obj = Nothing
End Sub
However, I use a program that calls upon Excel's object. I call Excel's object so often in so many different routines, I decided to make a function to make things simpler:
Public Function appXL As Object
Set appXL = GetObject(, "Excel.Application")
End Function
Although that is an extremely simple function, there is no way for me to release the object appXL
at the end of any subroutine I use, at least as far as I am aware. But a bigger concern that I have is that a subroutine that uses appXL
100+ times is actually grabbing the object the same number of times.
I honestly don't see why it would be a big issue since I am using GetObject
as opposed to CreateObject
. I am not creating a new instance of Excel everytime the function is called, so is this something that I should be concerned about when coding? Do I just need to completely get rid of the function and declare appXL
on every routine I use so I am able to release it in the end?