Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Code Execution has been Interupted" Msg Box 1

Status
Not open for further replies.

wwebb

Technical User
Mar 12, 2002
5
US
How do I stop the &quot;Code Execution has been Interupted&quot; Message box appearing after manually stopping my VBA program? Want to automatically exit the Excel routine by using the <Esc> key. I have tried: &quot;Application.DisplayAlerts=False&quot; with no success.
 
To disable User Control:
ThisWorkbook.UserControl = False

Don't forget to reset it:
ThisWorkbook.UserControl = True
 
I tried using the code and got an error message:
&quot;Object doesn't suopport this property or method&quot;.
 
Crazy! I knew the property name and the example in help showed using ThisWorkbook. Looking at what it applies to and checking the object browser, it looks like that property belongs to the Application object. In short:

Application.UserControl = True/False
 
I already tried that --- still get the same message box &quot;Code Execution has been interupted&quot;. When I hit debug - I always seem to end up on an &quot;End With&quot; line. This &quot;end with&quot; is part of a &quot;with&quot; that goes out to the Web and pulls data into a spreadsheet:

&quot;With ActiveSheet.QueryTables.Add(Connection:= ....&quot;
.Name = &quot;Web_Query&quot;
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = True
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCell
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebPreFormattedTextToColumns = False
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With

This &quot;End With&quot; is where I continue to hang up -- when I hit the debug key.

Also - thought there may be some way for me to specially address the &quot;Code Eexeecution...&quot; box itself so it is hidden or does not open. Thx for all your help. Your thoughts would be greatly appreciated.
 

Quoting from the book of help (with a little modification)

Code:
Sub mytest()

On Error GoTo handleCancel
Application.EnableCancelKey = xlErrorHandler
MsgBox &quot;This may take a long time: press ESC to cancel&quot;

Do
  Beep
Loop

handleCancel:
If Err = 18 Then
    MsgBox &quot;You cancelled&quot;
End If

End Sub


This will allow you to escape out of a VBA process and send you to a custom error handler which gives your custom message or even no message at all if you choose. Enjoy!
 
Fantastic. Took out the beep and the loop. Works Great!!! Thanks so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top