1

I'm working on an Add-In/Reference in excel VBA. At the top of the Add-In I want to put a function which backs-up and saves the add-in. I've coded the following, but keep getting the error "Code execution has been interrupted" on the "End Sub" line:

Sub SaveEditsToAddIn()

    DateAndTime = Format(Now, "yyyymmdd-hhmmss")

    Dim xlobj As Object
    Set xlobj = CreateObject("Scripting.FileSystemObject")
    xlobj.CopyFile "c:\File.xlam", "c:\backup\File " & DateAndTime & ".xlam", True
    Set xlobj = Nothing

    ThisWorkbook.Save

End Sub
  • why is this a Function? if it's not returing anything ? it should be a regular `Sub` – Shai Rado Aug 27 '17 at 15:43
  • I did change it to a sub, the error was the same. The original reason it was a function was just because I was creating it in a function dictionary and out of habit created it as a function. –  Aug 27 '17 at 15:46
  • I changed it to reflect the correctness of your comment. –  Aug 27 '17 at 15:48
  • Your code "works on my machine". Does this link help? https://stackoverflow.com/questions/2154699/excel-vba-app-stops-spontaneously-with-message-code-execution-has-been-halted – JensS Aug 27 '17 at 15:51
  • same here, you sure you have access to write to `"C:\"` ? – Shai Rado Aug 27 '17 at 15:52
  • Actually, after reading the post here: https://optionexplicitvba.com/2013/08/22/the-two-worst-excel-errors-ever/ I rebooted the machine and everything is working fine. It seems like it is some bug related to breakpoints and memory handling in excel(?). Thanks for the tips and the links! –  Aug 27 '17 at 16:01

0 Answers0