PC Review


Reply
Thread Tools Rate Thread

Close doesn't always close

 
 
omnicrondelicious@gmail.com
Guest
Posts: n/a
 
      28th Aug 2007
Greetings all,

I need to pick your collective brains again since I couldn't find this
exact issue in the archives. I've got a workbook which looks in a
particular directory on a fileserver, and loops through each .xls
file: opening, copying some key bits, pasting, and then closing each.
There's roughly 50 excel files in the directory that this workbook
deals with. Everything seems to work fine except at the end of the
run, there's usually a half-dozen files left open. All the others were
successfully closed, but not these brave few. This has become
something of a proud nail for me - it's really only a minor
inconvenience, but it's starting to bug the heck out of me. ;^)

Here's what I'm doing (Excel 2007 by the way):

Sub PullData()
'declarations and other stuff snipped

File = Dir(CStr(SrcDir & "\*.xls*"))
Do While Len(File) > 0

'open each workbook
Set srcWbk = Workbooks.Open(SrcDir & "\" & File)

'does a bunch of copy/paste stuff here, snipped


srcWbk.Close True
File = Dir

Loop
End Sub


Any thoughts? That srcWbk.Close bit just seems to get ignored around
15% of the time.

thanks!

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      28th Aug 2007
Here is one scenario that could cause such a condition:

There is a line: Application.DisplayAlerts = False
There are changes in the culprit files that occur that would normally
trigger the "Do you want to save changes" message but you don't see it
because the Application.DisplayAlerts = True command is after the
srcWbk.Close command.

Just a guess, but it has to be something close to that.

"(E-Mail Removed)" wrote:

> Greetings all,
>
> I need to pick your collective brains again since I couldn't find this
> exact issue in the archives. I've got a workbook which looks in a
> particular directory on a fileserver, and loops through each .xls
> file: opening, copying some key bits, pasting, and then closing each.
> There's roughly 50 excel files in the directory that this workbook
> deals with. Everything seems to work fine except at the end of the
> run, there's usually a half-dozen files left open. All the others were
> successfully closed, but not these brave few. This has become
> something of a proud nail for me - it's really only a minor
> inconvenience, but it's starting to bug the heck out of me. ;^)
>
> Here's what I'm doing (Excel 2007 by the way):
>
> Sub PullData()
> 'declarations and other stuff snipped
>
> File = Dir(CStr(SrcDir & "\*.xls*"))
> Do While Len(File) > 0
>
> 'open each workbook
> Set srcWbk = Workbooks.Open(SrcDir & "\" & File)
>
> 'does a bunch of copy/paste stuff here, snipped
>
>
> srcWbk.Close True
> File = Dir
>
> Loop
> End Sub
>
>
> Any thoughts? That srcWbk.Close bit just seems to get ignored around
> 15% of the time.
>
> thanks!
>
>

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      28th Aug 2007
Or, it could be that the network becomes temporarily unavailable and ignores
your close/save instruction. You could use Wait or Timer to test whether
the file is still open after a certain interval and, if so, try to close
again, counting the times you try to close up to, say, 10. Of course, that
would slow down your program. James

"JLGWhiz" <(E-Mail Removed)> wrote in message
newsFB9EF4F-99E3-4E4B-AB4F-(E-Mail Removed)...
> Here is one scenario that could cause such a condition:
>
> There is a line: Application.DisplayAlerts = False
> There are changes in the culprit files that occur that would normally
> trigger the "Do you want to save changes" message but you don't see it
> because the Application.DisplayAlerts = True command is after the
> srcWbk.Close command.
>
> Just a guess, but it has to be something close to that.
>
> "(E-Mail Removed)" wrote:
>
>> Greetings all,
>>
>> I need to pick your collective brains again since I couldn't find this
>> exact issue in the archives. I've got a workbook which looks in a
>> particular directory on a fileserver, and loops through each .xls
>> file: opening, copying some key bits, pasting, and then closing each.
>> There's roughly 50 excel files in the directory that this workbook
>> deals with. Everything seems to work fine except at the end of the
>> run, there's usually a half-dozen files left open. All the others were
>> successfully closed, but not these brave few. This has become
>> something of a proud nail for me - it's really only a minor
>> inconvenience, but it's starting to bug the heck out of me. ;^)
>>
>> Here's what I'm doing (Excel 2007 by the way):
>>
>> Sub PullData()
>> 'declarations and other stuff snipped
>>
>> File = Dir(CStr(SrcDir & "\*.xls*"))
>> Do While Len(File) > 0
>>
>> 'open each workbook
>> Set srcWbk = Workbooks.Open(SrcDir & "\" & File)
>>
>> 'does a bunch of copy/paste stuff here, snipped
>>
>>
>> srcWbk.Close True
>> File = Dir
>>
>> Loop
>> End Sub
>>
>>
>> Any thoughts? That srcWbk.Close bit just seems to get ignored around
>> 15% of the time.
>>
>> thanks!
>>
>>



 
Reply With Quote
 
omnicrondelicious@gmail.com
Guest
Posts: n/a
 
      28th Aug 2007
Hey gang, thanks for the input. I made one change that seems to have
fixed it:

srcWbk.Close SaveChanges:=False

After looking into what changes were being made in the source file,
it's clear none needed to be saved. Problem solved!

thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
docmd.close forms - doesn't close the form Wuelf Microsoft Access Reports 1 18th Nov 2008 01:05 PM
Excel shoud not close all active books when clicking close button =?Utf-8?B?dGVjaG5vbWlrZQ==?= Microsoft Excel Misc 0 10th Jun 2005 05:35 PM
Close all programs / Shut Down windows does not auto close outlook =?Utf-8?B?TUtlcw==?= Microsoft Word Document Management 2 22nd Aug 2004 11:11 PM
The Close (X) button of IE6 doesn't close Joseph Windows XP Basics 3 4th Oct 2003 12:11 AM
Save and Close doesn't close Will Microsoft Outlook Program Addins 3 7th Aug 2003 04:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:29 PM.