End Macro Question


Posted by Kristy on December 07, 2001 1:28 PM

I have a macro set up to open two workbooks, then bring up the Open window to choose the third. If I hit 'Cancel', I get 'Run-time error 1004' and that 'False.xls could not be found.'

Is there any way to have the macro simply end if I hit cancel?

Posted by Dan on December 07, 2001 2:00 PM

There is a pretty good tutorial on using error handlers in macros on Microsofts website. Check it out. If you are still having problems, just let us know!

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q213637

Posted by Kristy on December 07, 2001 2:13 PM

I *think* I understand that. Don't have the time now to try it, though (time to leave!:)

At any rate, that says that it is for Excel 2000. Currently, I'm running Excel 97. Think it would work for that too?

Posted by Joe Was on December 07, 2001 3:40 PM

Top of Sub below Dim's if any!

On Error GoTo myErr

Your code here!

End
myErr:
End Sub

This format will exit the macro on any error. JSW

Posted by Ivan F Moala on December 07, 2001 7:10 PM

The reason for he runtime error is because you
have not assigned anything in the event that
the user presses Cancel. If the user presses
cancel the result returned is False. I'm guessing
that you have a string variable assigned something
like Filename = app.getopenfilename & ".xls"
hence the False.xls

try putting in something along the lines of

If filename = False then End or Exit Sub depending
on if the routine was called via another macro.

Ivan



Posted by Dan on December 08, 2001 9:41 AM

Yes, works for Excel 97 too.