Error Handling

  • Thread starter Burnnie Holliday
  • Start date
B

Burnnie Holliday

I have a problem with the following subroutine. The files that it opens are
located in one of two locations, and it accomplishes this regardless of what
folder the file is located in. The problem is that it pauses execution
everytime any line in that particular subroutine gets run. What's more
confusing is that before, it worked perfectly, and seemingly without any
changes, suddenly this bug cropped up.

Sub OpenMatFile(FileName As String)

On Error Resume Next

Workbooks.Open MatPath & FileName, UpdateLinks:=False, ReadOnly:=True

If Err.Number <> 0 Then
Workbooks.Open MatPath & "2009 Material Archives\" & FileName,
UpdateLinks:=False, ReadOnly:=True
End If

End Sub
 
B

Bob Bridges

What do you mean by "pause", Burnnie? Does it run reeaaallly sloooowwwly,
like one or two seconds for each statement (and how do you know?)? Or do you
mean it stops after every statement and asks you to hit a button to proceed
(and if so how does it do that and what button do you hit)? Or what?

Oh, and what do you mean by "seemingly without any changes"? Do you mean
that there were changes but they were really really minor (and if so, what
were they)? Or do you mean you don't know of any changes at all but there
must have been a change because now it acts differently? Or what?
 
B

Burnnie Holliday

I mean that a dialogue box will appear as if I've pressed Ctrl+Break, giving
me the option to continue, end, or debug. If I choose to debug, I can see
that the code has stopped immediately after the successful execution of the
command.

And by without any changes, I mean that I have been working on a different
part of the same module, without altering the portion of code that calls the
subroutine in question.

The behavior seems to have disappeared now, though. I have no idea what it
was. However, I don't need this to sneak up on me during a presentation. Do
you see any errors with the subroutine at all?
 
B

Bob Bridges

Whenever I get that dialogue box you speak of, there's an error message in
it. It says things like "object is required" or "the last action was
canceled by user" or "this method not supported by object", that sort of
thing. You sound reasonably experienced, though, and you wouldn't have told
me an error message pops up without bothering to read the error message.
Tell me you wouldn't have, please.

But then, if there's no error message then you would have seen a completely
blank box with just the three buttons on it; and I've never seen one of
those. Neither have you, perhaps, and you would have mentioned it as
surpassingly unusual - but you didn't. So I don't know what to think now.
What does the dialogue box SAY?

As for the program...well, I suppose MapPath can be counted on to end in a
backslash, right? If MatPath is set by logic rather than being a constant,
and if that logic is capable of omitting the final "\" unexpectedly, it could
result in an intermittent error. But in that case you would've seen an ERROR
MESSAGE, which you don't mention and therefore could not have happened, right?
 
B

Burnnie Holliday

No, it isn't any sort of error message. All it would say was that code has
been terminated (sorry, I don't know why I've been omitting that), which
isn't much information at all of why it was terminated, or otherwise I could
bugfix that rather easily. I've given the full code some extensive runs now,
though, and the error hasn't managed to duplicate itself. That alone should
set me at ease since as it stands now, that particular peice of code gets
executed twice during the macro, and an almost identical subroutine opens
files 22 times. I've given our network quite the workout beta testing this
thing.

Yes, MatPath is a string constant ending in "\" defined during the module
declarations. As long as it isn't a glaring error, then I will chalk it up
to a random occurence, that I must have caused some sort of variable
confusion somehow that made Excel to force a stop in execution due to an
error that was masked by the error handling. That's my best guess, anyways.
I was hoping somebody with a bit more experience might have a better clue.
 

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