Code stops for no reason (that I can think of)

D

Daniel Bonallack

I built a short and simple procedure on my PC, tested it, converted it to an
xla, and made a button. I installed this button on a couple of colleagues'
PCs.

On only one PC, when the button is pressed, about a third of the macro runs,
then the debug window shows, saying the code has been interrupted (as if I
had pressed "Ctrl+Break"). If I hit "Continue", it then happily runs the
rest of the code as if no problem ever existed.

Do you know why, on one PC, Excel is acting as if I had pressed "Ctrl +
Break"?

thanks in advance
Daniel
 
R

Rick Rothstein

I think we will need to see your code (in order to see exactly what you are
doing) before being able to make a guess as to what is going on. If you do
post your code, indicate the line it is stopping on (just in case we can't
duplicate your results on our systems).
 
B

Bob Umlas

Vista, Excel 2007, right? We've encountered this and have not yet found a
workaround. Instructions to our users is to just click continue. Still
trying to set it up so it happens consistently so we can report to
Microsoft, but so far it seems pretty random, although with a particular
application it happens very frequently. There's NO reason this should
occur -- I pretty much know what I'm doing and for it to say code execution
has been interrupted on a statement like End Sub is ridiculous!!
I'm afraid you're going to have to just live with it!
Bob Umlas
Excel MVP
 
D

Daniel Bonallack

Thanks Rick and Bob,

I should have included this in the original paragraph, but it's actually
Excel 2003, Windows XP.

Here is the first part of the code:

_________________

Sub CreateOutput2()

MsgBox "You will be asked to open a file to check these deals against for
duplicates", vbOKOnly + vbInformation

blnNew = False

sActive = ActiveWorkbook.Name
Application.Dialogs(xlDialogOpen).Show
sCheck = ActiveWorkbook.Name
sCheckSh = ActiveSheet.Name
If sCheck = sActive Then End


The macro stops on the line "sCheck = ActiveWorkBook.Name".

I haven't defined my variables - do you think that could be it?

regards
Daniel
 
J

Jim Thomlinson

Have you re-booted the computer where the error is occuring? I have had the
same experience that was fixed with a reboot...
 
R

Rick Rothstein

Your code does not "stop" for me, so Jim's suggestion may end of working for
you. I do see a problem in the code you posted, though... you use an End
statement to shut down your code. Over in the compiled VB world I originally
came from, doing that could produce unwanted results (especially if objects
were involved) as the End statement stopped all running code and didn't give
the operating system an opportunity to do automatic (behind the scenes)
clean ups that might be necessary depending on what the code is actually
doing. I'm not sure if the same thing applies to VBA, but I would still not
use End to stop my code. VB has an Exit Sub (also Exit Function for
functions) which closes down running code and it is my understanding that it
allows for any behind the scenes clean ups that may be necessary.
 

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