View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Not Enough Memory to run Microsoft Office Excel.

Your code appears to clear the objects, but if anything overkill !
Why PostMessage WM_QUIT or proc.Kill() when you have already done
appXL.Quit.
Which xl version is giving you problems, if xl2k/xl97 maybe this -

iHandle = FindWindow(Nothing, appXL.Caption)
which follows after you have done appXL.quit !

In passing, I'd change that API call -
appXL.Caption = "tempUniqueCaption" ' strong possibility of multiple apps
ruining
iHandle = FindWindow("XLMAIN", appXL.Caption)
and you could use your postMessage with the older versions with iHandle (to
replace appXL.hWnd) ) iso proc.kill

Are you absolutely sure there are no other objects anywhere in your code?
Might be worth making Excel visible before closing it.

Perhaps Excel is not the problem at all, anything else you can think of.
Does your own app quit properly.

Regards,
Peter T


"Norra" wrote in message
...
Peter,
Absolutely, I wrote a procedure that I call, called KillExcel and I call
this after every instance of an excel object being opened.

Public Sub KillExcel(ByRef objws As Excel.Worksheet, ByRef objWb As
Excel.Workbook, ByRef appXL As Excel.Application, _
Optional ByVal strSaveAs As String = "", _
Optional ByVal bSave As Boolean = False, _
Optional ByVal bProtect As Boolean = False)
Dim proc As System.Diagnostics.Process
Dim intPID As Integer
Dim intResult As Integer
Dim iHandle As IntPtr
Dim strVer As String

If bProtect Then objws.Protect("password", True, True, True)
If bSave Then
appXL.DisplayAlerts = False
objWb.SaveAs(strSaveAs)
appXL.DisplayAlerts = True
End If
If Not (objws Is Nothing) Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objws)
'You must call this if you are using Excel 11.0 Object Library
objws = Nothing
End If
If Not (objWb Is Nothing) Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objWb)
objWb = Nothing
End If
If Not (appXL Is Nothing) Then
appXL.Caption = "TRAKKER Excel"
appXL.DisplayAlerts = False
strVer = appXL.Version
iHandle = IntPtr.Zero
appXL.DisplayAlerts = True
appXL.Quit()
If CInt(strVer) 9 Then
PostMessage(appXL.Hwnd, conWM_QUIT, 0, 0)
Else
iHandle = FindWindow(Nothing, appXL.Caption)
intResult = GetWindowThreadProcessId(iHandle, intPID)
proc = System.Diagnostics.Process.GetProcessById(intPID)
proc.Kill()
End If
System.Runtime.InteropServices.Marshal.ReleaseComO bject(appXL)
appXL = Nothing
End If
End Sub


"Peter T" wrote:

Are you sure you release all object references before you Quit your

Excel,
eg

Set objWSheet = Nothing
objWBook.close true (false)
Set objWS = Nothing
xlApp.Quit
Set xlApp = Nothing

Without knowing your app there maybe other references too, they are not
always obvious. But if they are left clinging you won't be able to fully
terminate your Excel instance, hence rapid memory leak if you are

repeatedly
creating new instances.

Regards,
Peter T

"Norra" wrote in message
...
I have a windows application that runs constantly and an Outlook

Add-in.
In
the add-in, I am stripping attachments off of emails and putting them

in a
folder on the local machine for the winapp to pick up and process. In

the
winapp I am opening excel files programatically, reading the data &

closing
the excel file. I am creating a new excel application object using
Excel.Application and kill this object after user. This code is

getting
executed very often throughout the day.

After a random amount of time I get an error message of "Not Enough

Memory
to run Microsoft Office Excel. Please Close other applications and try

again".

I have WinXP Pro, 3Ghz, with 2GB RAM using Office 2003 Enterprise. I

have
set the paging size to 3070 with a max of 4096, because that is the

max it
would let me set it to. Once I get this error, I am forced to restart

the
system if I want to get into any of the Office Applications or allow

my
winapp to continue to process, as when this error shows up it disables

all
applications not just Excel. I will get the same message if I try to

open
Word, Powerpoint or Access as well.

I have updated Office to SP2 and all the latest security patches with

great
antcipation that it would solve the problem. Didn't happen!!! Can

someone
please help in my crisis?