我正在使用excel VBA中的加载项/引用。在加载项的顶部我想放置一个备份和保存加载项的函数。我编写了以下代码,但在“End Sub”行中不断收到错误“代码执行已被中断”:
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