View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Cannot close a workbook in VBA due to Run-Time error '1004'

This code works. I can't tell why from one statement what your problem is.
Maybe you forgot to use SET when you declared wkbk

Sub test()

Workbooks.Open Filename:= _
ActiveWorkbook.Path & "\" & "tempfile.xls"

Set wkbk = ActiveWorkbook

wkbk.Close
End Sub


"Tom Med" wrote:

When I try to call this method

wkbk.Close

I get this error message

Run-Time error '1004'

Method 'Close' of object '_Workbook' failed

If I step through the code it will close fine, but the bit of code
that seems to be causing a problem is the
Sub Workbook_Deactivate()
breaking into this in the debugger seems to resolve the issue, so I
cannot find the cause of the problem. Is there an error in the way
excel handles the close events? It seems something is fundamentally
wrong with the way excel is working in this senario.

Thanks
Tom