View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 2,203
Default Device I/O Error

Interesting that it continues to work without error. I opened a new
workbook, set up a userform with a command button and put the 2 statements in
it, as you originally had them. Saved it all "just in case" (a good thing).
When I clicked the button I got an Excel (2003) has stopped running error.
Took out the Unload Me statement and I still got the same error with just the
ThisWorkbook.Close False
statement in it.

Might be a better thing if you set a global flag in the routine to test on
return and do the close in a regular code module if you experience any
problems later on with this piece. Code might look something like this:

Private Sub CommandButton1_Click()
globalCloseWorkbookFlag = True
Unload Me
End Sub

then back in your code that called the UserForm, it might look something
like this
up in a declaration section of a module you'd have
Public globalCloseWorkbookFlag as Boolean

then down in the code that calls the UserForm:

.... other code ahead of this section
globalCloseWorkbookFlag = False
UserForm1.Show
If globalCloseWorkbookFlag Then
ThisWorkbook.Close False
Exit Sub
End if
.... more code for when the workbook is not to be closed


Sub
"JMay" wrote:

Thanks JLatham;
Your logic makes total sense. I removed the Unload me (line) and things
seem to be working better.
Jim

"JLatham" wrote:

Generally, "Device I/O Error" is hardware related. You might give strong
consideration to making sure you have a good backup strategy in place for
whatever drive you are using to save those files on.

BTW: You shouldn't even need the "Unload Me" statement in your sub ... it's
going to be unloaded when the ThisWorkbook.Close statement executes.

The Unload Me may even be confusing things (haven't tested it) because
Unload means to take it out of memory, which would, in theory at least,
remove the code in it also.

"JMay" wrote:

After stepping thru my code I'm getting the aboce message.
What does this usually mean? Any hints would be helpful.