方法一:设置Workbook.Saved属性为True 在关闭工作簿之前,将Workbook.Saved属性设置为True,可以欺骗Excel认为工作簿已经保存,从而在关闭时不会弹出保存提示。 vba Private Sub Workbook_BeforeClose(Cancel As Boolean) ThisWorkbook.Saved = True End Sub 这段代码应该放在ThisWorkbook对象的Workbook_BeforeClose事件中。当...
Developing the Macro to Close a Workbook Without Saving Using Excel VBA ⧪ Method 1 – Opening the VBA Window Press ALT + F11 on your keyboard to open the Visual Basic window. ⧪ Method 2 – Inserting a New Module Go to Insert > Module in the toolbar. Click on Module. A new modu...
After making changes to Excel file, if you attempt to close the workbook without saving it first, Excel displays a Prompt window saying, “Want to save your changes to…”. Similar prompts are displayed when users try to save files in different formats, such as xlsx to xlsm. 3 Examples ...
Sub CloseWorkbookWithoutSaving() ThisWorkbook.Close SaveChanges:=False End Sub ``` 💡 小贴士:这样关闭工作簿,不会保存你做的任何更改哦!2️⃣ 保存并关闭工作簿: ```vba Sub SaveAndCloseWorkbook() Dim wb As Workbook Set wb = ThisWorkbook wb.Close SaveChanges:=True End Sub ``` 💡 小贴士...
在有些情形下,我们可能需要找到指定文件夹中最新保存的工作簿,然后对其进行处理。例如,每天上班前系统...
8 关闭工作簿而不保存Close a Workbook without Saving Sub mynzvba_close_Activeworkbook() ActiveWorkbook.Close SaveChanges:=False End Sub 本节内容参考程序文件:Chapter03-2.xlsm 9 保存并关闭工作簿Close a Workbook after Saving Sub mynzvba_close_workbook() ...
其中包含三个事件:New、Open和Close,可以从列表中选择“Close”或“Open”以插入Document_Close()或...
Step 3:Use the ALT/F11 keys to go back to Excel and run the macroproLessson17c. The value 695 is entered in cell A1 and the following message box appears Step 4:Close Excel without saving anything. You can use the message box to inform the user. You might also ask the user (with...
Step 5:Close Excel without saving anything We hope you have enjoyed this introduction to lesson 11 for more on this topic and a complete course on Excel macros download the Tutorial on Excel Macros Next Lesson:Managing VBA Coding Errors
Method 1 – Save and Close Active Workbook by Using Excel VBA Steps: From theDevelopertab, selectVisual Basic. Alternatively, you can pressALT + F11to do this too. The “Microsoft Visual Basicfor Application” will appear after this.