Hi everyone.
This is a big day, my first vbforums post!
I have a macro that calls Excel from another program, does some stuff, and exits Excel. My problem is that it doesn't really exit Excel. The Excel window will close but the program remains in Windows memory. This becomes a problem when I try to run the macro a second time.
If I go into the Task Manager and kill Excel, the macro generally works. Naturally, this isn't a viable solution for the end user.
A sample of my VBA code follows:
VB Code:
Dim MyXL As Object Dim XLInputWorkbook As Object Dim XLOutputWorkbook As Object
Later...
VB Code:
Set MyXL = CreateObject ("Excel.Application") Set XLInputWorkbook = MyXL.Application.Workbooks.Open(FileName = "somepath") Set XLOutputWorkbook = MyXL.Application.Workbooks.Add
I do my stuff and when I'm ready to close Excel do the following
VB Code:
MyXL.Application.Quit Set MyXL = Nothing Set XLInputWorkbook = Nothing Set XLOutputWorkbook = Nothing
Should that not be enough?
I have also attempted to use a procedure to detect whether or not Excel is already running and use the current instance by calling
VB Code:
Set MyXL = GetObject("ExcelFilePath")
I am entirely new to programming so I don't doubt I'm making a huge error somewhere along the way. This problem has plagued me for months and I've checked and double checked to ensure I'm not forgetting to release variables or offer the correct sacrifices to the VB gods.
Thanks for the help
Mike




Reply With Quote