help with on error stuff

M

Matthew Dyer

I want my code to stop altogether when it hits this particular error.
I'm thinking it might be easiest to do the on error <label>, and call
a seperate sub/function to quit out of the macro, so here's what I've
got so far:

On Error GoTo file_error:
foldername = MyPath & Format(Now, "mm-dd-yyyy") & "\"
MkDir foldername

file_error:
MsgBox "The Save To Directory Does Not Exist", vbOKOnly
Call macro_quit

What code would I put into macro_quit to quit our of the entire
process? Is there a code I could put in the file_error label and skip
the macro_quit call altogether?
 
M

Matthew Dyer

I want my code to stop altogether when it hits this particular error.
I'm thinking it might be easiest to do the on error <label>, and call
a seperate sub/function to quit out of the macro, so here's what I've
got so far:

    On Error GoTo file_error:
    foldername = MyPath & Format(Now, "mm-dd-yyyy") & "\"
    MkDir foldername

file_error:
        MsgBox "The Save To Directory Does Not Exist", vbOKOnly
        Call macro_quit

What code would I put into macro_quit to quit our of the entire
process? Is there a code I could put in the file_error label and skip
the macro_quit call altogether?

Figured it out! used an additional ExitHere label with the Exit Sub
command

On Error GoTo file_error:
foldername = MyPath & Format(Now, "mm-dd-yyyy") & "\"
MkDir foldername

file_error:
MsgBox "The 'Save To Directory' in Worklist Detail Format Does
Not Exist!", vbOKOnly
Resume ExitHere
ExitHere:
Exit Sub
 
G

Gord Dibben

Without knowing what you have done so far..........

file_error:
MsgBox "The Save To Directory Does Not Exist", vbOKOnly
Exit Sub

You may have to reset things like screenupdating and calculation mode etc
before the Exit Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top