I have been working on an .xlsb file in Office Excel 2016. I have developed Macros within the VBA project and it has worked fine (up to v25 of the file) with over 3 months of work.
Now I need to make some adjustments to the VBA Macros. When I save and close the file, the VBA code changes are lost when the file is next opened (Windows recognised the correct last saved-date though).
The file does have Macros in the Workbook_Open and Workbook_BeforeClose events, but nothing that has been changed since it worked fine. Of note, there is no Workbook_BeforeSave event in the VBA project.
Troubleshooting steps I have tried:
- Removing the Workbook_BeforeClose event in parts and then entirely
- Creating a new file from scratch and copying in the VBA code
- Saving in both the VBA Editor window and the Excel Application window
- Saving as a new filename
Here is the entire ThisWorkbook module, in case it helps:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Picking").Delete
Sheets("Ordering").Delete
Clear_UI
Dim UI As Worksheet
Set UI = Sheets("User Interface")
With UI
.Shapes("Menu_StartNewEvent").OnAction = ""
.Shapes("Menu_UpdateEvent").OnAction = ""
.Shapes("Menu_ProduceSheets").OnAction = ""
.Shapes("Menu_CountIn").OnAction = ""
.Shapes("Menu_EditPackages").OnAction = ""
.Shapes("Menu_EditCocktails").OnAction = ""
.Shapes("Menu_EditInventory").OnAction = ""
End With
Unhide_Them
Set UI = Sheets("Inventory Editor")
UI.Shapes("SaveButton").OnAction = ""
Set UI = Sheets("Cocktail Editor")
UI.Shapes("SaveButton").OnAction = ""
Set UI = Sheets("Package Editor")
UI.Shapes("SaveButton").OnAction = ""
Hide_Them
Application.DisplayAlerts = True
ThisWorkbook.Save
End Sub
Private Sub Workbook_Open()
On Error Resume Next
Application.DisplayAlerts = False
ThisWorkbook.Windows.Item(1).Caption = Replace(ThisWorkbook.Windows.Item(1).Caption, " [Repaired]", "")
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Name, AccessMode:=xlExclusive
ThisWorkbook.Saved = True
Application.DisplayAlerts = True
Dim UI As Worksheet
Set UI = Sheets("User Interface")
With UI
.Activate
.Shapes("Menu_StartNewEvent").OnAction = "ThisWorkbook.Start_New_Order"
.Shapes("Menu_UpdateEvent").OnAction = "ThisWorkbook.Update_Event_Details"
.Shapes("Menu_ProduceSheets").OnAction = "ThisWorkbook.Build_Only_Picking_Sheet"
.Shapes("Menu_CountIn").OnAction = "ThisWorkbook.Build_Only_Picking_Sheet"
.Shapes("Menu_EditPackages").OnAction = "Edit_Packages"
.Shapes("Menu_EditCocktails").OnAction = "Edit_Cocktails"
.Shapes("Menu_EditInventory").OnAction = "Edit_Inventory"
End With
Clear_UI
Set UI = Sheets("Inventory Editor")
UI.Shapes("SaveButton").OnAction = "Save_Inventory_Editor"
Set UI = Sheets("Cocktail Editor")
UI.Shapes("SaveButton").OnAction = "Save_Cocktail_Editor"
Set UI = Sheets("Package Editor")
UI.Shapes("SaveButton").OnAction = "Save_Package_Editor"
Hide_Them
End Sub
I have looked at question/answer here: StackOverflow:xla-file-not-saving-in-excel-2010