LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default closing opened workbook/app in memory

How could I close a workbook in a case of an error or if it was opened by a
program and wasn't closed when I start the program again?
(I have many workbooks to be opened and closed.)
I'm opening a workbook as follows:
Dim xlapp As New Excel.Application

Set xlbook = xlapp.Workbooks.Open(strOurFileName, True)
logFlagApp = True ' setting a flag that it was opened
....
'********** In addition I'm checking whether it's opened by using the
following:
Function FileLocked(strFileName As String) As Boolean
On Error Resume Next

Open strFileName For Binary Access Read Lock Read As #1
Close #1

If Err.Number < 0 Then
FileLocked = True
Err.Clear
End If

End Function
'*********************
.....
ErrorHandling_Err:
If Err Then
If logFlagApp = False Then

Else
xlapp.ActiveWorkbook.Save
xlapp.Quit
logFlagApp = False
End If
Else

Resume ErrorHandling_Exit
End If

When the program opened the workbook and didn't close it I'm trying to use
this by inserting it into the code during debugging:
Excel.ActiveWorkbook.Close
but it's not working. There is some mistake about an object. Somehow it was
working before.

Thanks,

Alex
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opened Autosave but when closing workbook Autosave closes itself Ken Excel Worksheet Functions 0 October 29th 05 05:11 PM
Opening a workbook if not opened, going to it if already opened neotokyo[_3_] Excel Programming 0 September 24th 04 08:56 PM
Opening a workbook if not opened, going to it if already opened neotokyo[_2_] Excel Programming 1 September 24th 04 07:17 PM
Opening a workbook if not opened, going to it if already opened neotokyo Excel Programming 1 September 24th 04 06:33 PM
How to see if the opened workbook is opened by another user ? balexis Excel Programming 1 August 18th 04 04:11 PM


All times are GMT +1. The time now is 07:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"