Runtime Error 5 saving workbook with Microsoft 365

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

When I manually save the workbook the below code inserts the last time I manually saved the workbook into cell A1 of sheet 'Training Log' (named "SaveTime").

This has worked without any problem for years, but I have just converted from Office 2021 to Microsoft 365 and now it errors Runtime Error 5.
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False
Range("SaveTime") = "Last saved" & Format(Time, " h:mmam/pm") & ", " & Round(FileLen(ActiveWorkbook.FullName) / 1000000, 1) & "Mb"

Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

Can you tell me what I need to change to make this work again?

Many thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
See here: VBA Invalid Procedure Call Or Argument Error (Error 5)

I am guessing that the issue is with this line:
Rich (BB code):
Range("SaveTime") = "Last saved" & Format(Time, " h:mmam/pm") & ", " & Round(FileLen(ActiveWorkbook.FullName) / 1000000, 1) & "Mb"
as that is really the only line of code doing anything.

What I would recommend is breaking it into parts to test it out, slowly add each piece back in until the error occurs. then you will know what the issue is.
(So each component is colored).

So start off like this:
Rich (BB code):
Range("SaveTime") = "Last saved"
and see if that works. If it does, add in the next piece and test it out again, etc.

Once you know which piece is causing the error, you can focus on it to try to fix it.
 
Upvote 0
Many thanks for your help Joe.

It turns out the issue was a Microsoft Office versions glitch because I was running Office 2021 and Office 365 at the same time - I uninstalled Office 2021 and the issue was resolved.

Thanks again.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,593
Messages
6,125,715
Members
449,254
Latest member
Eva146

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top