-2
我有一個.xlsm文件,我想在運行宏時自動打開它。在保存之前和關閉之前,當前文件將文件保存爲.xls在具有不同名稱的不同位置。然而,在關閉之前給我錯誤,宏自動運行也是如此。這是我的代碼。自動打開excel vba宏,beforeclose和beforesave
Private Sub Workbook_Open()
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.ScreenUpdating = False
Application.DisplayAlerts = False ' so you can overwrite without warning
ActiveWorkbook.SaveCopyAs "C:\Users\name\Desktop\testing.xls"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Application.DisplayAlerts = False ' so you can overwrite without warning
ActiveWorkbook.SaveCopyAs "C:\Users\name\Desktop\testing.xls"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
ActiveWorkbook.save
End Sub
End Sub
您是否嘗試用'ThisWorkbook'替換'ActiveWorkbook'? – PatricK
只是爲了確認你的代碼是在** ThisWorkbook **而不是**模塊**中? – PatricK
什麼錯誤?錯誤信息是什麼意思?你是怎麼試圖解決它告訴你錯的? –