View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Closing a workbook programmatically

Hi Raul

Try this

Sub test()
Dim destWB As Workbook
Set destWB = Workbooks.Open("K:\AAAA\BBBB\CCCC\excelfile.xls")
MsgBox "By"
destWB.Close True ' false = not save and true = save
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Raul" wrote in message ...
I am loosely using the workbooks.open method to open a
workbook and then extracting some data from it. The
routine opens the workbook and gets the desired
information. However, I'd like to close the workbook
before moving on to other steps but I can't seem do it.

Can anyone help me out with this one?

.....
Workbooks.Open "K:\AAAA\BBBB\CCCC\excelfile.xls"
Set currentBook = Application.ActiveWorkbook
'do other stuff

Workbooks(currentBook).Close
....
The routine doesn't crash, it just doesn't close the
workbook. I don't need to save any changes to the file I
want to close. I also have other workbooks open that I
don't want closed.

Thanks,
Raul