I have the following code in a macro that works perfect on my machine and two other PC's. However, one client is having problems with the closing process. As the code stands, when we run the macro the Excel application closes down completely if no other workbooks are open or closes the related workbook and the macro, leaving any other workbook open. On this problem machine, the client gets a "Subscript out-of-range" 1004 error and nothing shuts down.
CODE:
Sub CloseMacro()
On Error Resume Next
intLoopCntr = 0
For Each wb In Application.Workbooks
If wb.Name = strInfileName Then
wb.Close (False)
intLoopCntr = intLoopCntr - 1
End If
intLoopCntr = intLoopCntr + 1
Next wb
If intLoopCntr = 1 then
Application.Quit
else
Workbooks(strMacroName).Close (False)
endif
End Sub
I took the looping and Application.Quit statement out and changed it to:
Sub CloseMacro()
On Error Resume Next
Workbooks(strInfileName).Close (False)
Workbooks(strMacroName).Close (False)
End Sub
On my machine, the macro closes down and leaves the Excel Application open but on her machine, I no longer get an error message but the macro does not close down.
We are both on Microsoft Office 2003 on a Windows 2000 platform so I don't understand why these codes work the way they should on my machine and doesn't on hers. Any ideas?
CODE:
Sub CloseMacro()
On Error Resume Next
intLoopCntr = 0
For Each wb In Application.Workbooks
If wb.Name = strInfileName Then
wb.Close (False)
intLoopCntr = intLoopCntr - 1
End If
intLoopCntr = intLoopCntr + 1
Next wb
If intLoopCntr = 1 then
Application.Quit
else
Workbooks(strMacroName).Close (False)
endif
End Sub
I took the looping and Application.Quit statement out and changed it to:
Sub CloseMacro()
On Error Resume Next
Workbooks(strInfileName).Close (False)
Workbooks(strMacroName).Close (False)
End Sub
On my machine, the macro closes down and leaves the Excel Application open but on her machine, I no longer get an error message but the macro does not close down.
We are both on Microsoft Office 2003 on a Windows 2000 platform so I don't understand why these codes work the way they should on my machine and doesn't on hers. Any ideas?