+ Reply to Thread
Results 1 to 2 of 2

Code Execution has been interrupted

Hybrid View

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Code Execution has been interrupted

    I get the subject error message when I try to execute this code.

    At the moment, it stops on the DoEvents line. It really doesn't matter what I have on this line. It always fails at that point after opening the file successfully. However, I can start before opening the file and step though the code manually and it executes properly. There is no error number or description other than "I quit!"

    Option Explicit
    Global shD As Worksheet             ' Destination workhset
    
    Dim xlS As Workbook                 ' Source Workbook
    Dim shS As Worksheet                ' Source Sheet
    Dim PathName As String              ' Pathname to file
    Dim FileName As String              ' File name
    
    Sub OnOpen()
    Dim xlD As Workbook
    ' initalize variables
    PathName = ThisWorkbook.Path
    FileName = "athletes.xlsm"
    Set xlD = ThisWorkbook
    Set shD = Sheets("Blad1")
    
    ' Check for athelete file
    If Dir(PathName & "\" & FileName) = "" Then
        MsgBox "The file, " & FileName & " does not exist in the current directory.", vbOKOnly + vbCritical, _
            "File Name Does Not Exist"
        Exit Sub
    End If
    
    
    ' Open the file
    Set xlS = Workbooks.Open(PathName & "\" & FileName)
    ' Check that sheet exists
    'On Error GoTo MyExit
    DoEvents
    Set shS = xlS.Sheets("Athletes")
    
    xlD.Activate
    
    Exit Sub
    
    MyExit:
    MsgBox "Sheet, Athletes, does not exist in the workbook", vbOKOnly + vbCritical, "Sheet Does Not Exist"
    xlS.Close savechanges:=False
    
    End Sub
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Code Execution has been interrupted

    I was wondering what I did wrong with my coding until another program that I have been using daily for months started doing the same thing. It opened a file and fainted at the very next line. Closing and re-opening Excel did nothing, so I had to reboot. Both programs now execute properly at least as far as proceeding beyond file open. Now I have to back out all the debugging code I put in .

    It appears that a bad image of the excel executable was lurking somewhere in memory and could only be erased by "pulling the plug."

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Code execution has been interrupted
    By davidktilley in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2014, 12:09 PM
  2. Code Execution has been interrupted
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-11-2009, 09:39 AM
  3. Code execution has been interrupted
    By RitterSteve in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2007, 03:37 PM
  4. [SOLVED] Code Execution has been interrupted - ??
    By ina in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2006, 11:55 AM
  5. code execution has been interrupted
    By Who I Am in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2006, 08:00 AM
  6. [SOLVED] Code execution has been interrupted
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2006, 03:25 AM
  7. Code Execution Has Been Interrupted
    By LCK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2005, 08:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1