Excel-2007 problem while closing the files

M

Mahesh_D

Hi,

In Excel-2007 addin, in ShutDown functionality for closing all open files.

I have written following code:

Try
'Close All Open documents
Dim exlWorkBook As Excel.Workbook
If Application.Workbooks.Count = 1 Then
Application.ActiveWorkbook.Close(False)
Else
For Each exlWorkBook In Application.Workbooks
exlWorkBook.Close(False)
Next
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try


The exception is "Exception from HRESULT: 0x800AC472".



Any suggesstions will be helpful.

Thanks
Mahesh
 
J

Jim Cone

For Each exlWorkbook In Application.Workbooks
If Not ThisWorkbook Is exlWorkbook Then
exlWorkbook.Close False
End If
Next
--
Jim Cone
Portland, Oregon USA




"Mahesh_D"
<[email protected]>
wrote in message
Hi,
In Excel-2007 addin, in ShutDown functionality for closing all open files.
I have written following code:

Try
'Close All Open documents
Dim exlWorkBook As Excel.Workbook
If Application.Workbooks.Count = 1 Then
Application.ActiveWorkbook.Close(False)
Else
For Each exlWorkBook In Application.Workbooks
exlWorkBook.Close(False)
Next
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try

The exception is "Exception from HRESULT: 0x800AC472".
Any suggesstions will be helpful.
Thanks
Mahesh
 
M

Mahesh_D

Hi,

Thanks Jim for your reply.

I have tried code given by you:

Try
Dim exlWorkBook As Excel.Workbook
For Each exlWorkBook In Application.Workbooks
If Not Application.ThisWorkbook Is exlWorkBook Then
exlWorkBook.Close(False)
End If
Next
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try

But it leads to exception as: "Exception from HRESULT: 0x800A03EC"

This exception value is new as compared to last one which i got. It is
occuring because of line:
"If Not Application.ThisWorkbook Is exlWorkBook"



Thanks
mahesh
 
J

Jim Cone

I would assume then that your code is not in a workbook.
--
Jim Cone
Portland, Oregon USA



"Mahesh_D"
<[email protected]>
wrote in message
Hi,Thanks Jim for your reply.
I have tried code given by you:

Try
Dim exlWorkBook As Excel.Workbook
For Each exlWorkBook In Application.Workbooks
If Not Application.ThisWorkbook Is exlWorkBook Then
exlWorkBook.Close(False)
End If
Next
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try

But it leads to exception as: "Exception from HRESULT: 0x800A03EC"
This exception value is new as compared to last one which i got. It is
occuring because of line:
"If Not Application.ThisWorkbook Is exlWorkBook"
Thanks
mahesh
 
M

Mahesh_D

Hi Jim,

That code is written inside Excel addins ThisAddIn_Shutdown() event.
So it should work, but its not happening that way.



Thanks
mahesh
 
J

Jim Cone

I cannot help you - I am only aware of two workbook events that
might be similar to what you are using...

Private Sub Workbook_AddinUninstall()
- and -
Private Sub Workbook_BeforeClose(Cancel As Boolean)
--
Jim Cone
Portland, Oregon USA



"Mahesh_D"
<[email protected]>
wrote in message
Hi Jim,
That code is written inside Excel addins ThisAddIn_Shutdown() event.
So it should work, but its not happening that way.
Thanks
mahesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top