View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Vasant Nanavati Vasant Nanavati is offline
external usenet poster
 
Posts: 1,080
Default File won't close when "beforeclose" event is used.

Sorry, Libby; but I'm not familiar with the use of this "CloseSwitch"
variable, so I don't think I'm understanding the issue here.

If you don't get an answer in this thread, you might try reposting your
question with more detail.

--

Vasant

"Libby" wrote in message
...
Hi

I think this is a problem that has been mentioned before.

If I remember correctly a public boolean variable was used
as a kind of switch.
eg Public CloseSwitch

under the sub Workbook_Open set this to False

in the beforeclose code, use a select case to set it to
true if it's false.
The Select Case stops the workbook being opened, being
opened twice.

Public CloseSwitch

Sub Workbook_Open
CloseSwitch = False
end sub

Sub Workbook_BeforeClose
Select case CloseSwitch
Case False
CloseSwitch = True
Workbooks.Open "file to be opened"
ThisWorkbook.Close
end select
end sub



-----Original Message-----
I have an Excel file that opens up other files to
retreive info. Once the info is copied the files were to
be closed using the .close method. I could not figure out
why they wouldn't close. When I stepped through the VBA
code the files would close, but not when the code was
running by itself. I knew the files that I wanted to
close contained code in the beforeclose event. Once I
removed this code, the files closed as directed.
Is there a way around this? I've changed the files so
they no longer require code in the beforeclose event, but
I would like to know if this is a bug or if I have to add
something to allow code to be added to the beforeclose
event.
.