File is "Locked for editing by another user" "Locked for editing" while using autosave.

Mette85

New Member
Joined
Mar 29, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello,

I`m running a excel dokument that`s beeing used by 3 people randomly trough the day. When the dokument is opened it will start autosaving every 10 minute.. but i am getting error message when the "timers" meet or one of them opens the dokument at the same time. is there any way to ignore the message, and try to autosave again? without the meacro to stop running? atm i dont remember the error message, but i think its "Locked for editing by another user" or "Locked for editing". Reason for not posting the dokument is because the information on that one cannot be shared because its a facktory dokuement

This is the macro i`m running
Private Sub Workbook_Open()
SaveThis
End Sub

To autostart the macro

Sub SaveThis()
Application.DisplayAlerts = False
ThisWorkbook.Save

Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub

is the macro

Mvh
Mette
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Would recommend to use the AutoRecovery feature: Ribbon > File > Options > Save > tick check box Save AutoRecover information every .. minutes

If you want to keep using the OnTime method, then the scheduled time needs to be canceled before the workbook closes. If this is omitted, then Excel will continue to run this macro, even after the workbook has been closed as long as Excel is active. The workbook will then open automatically in order to run the scheduled macro and this may happen unattended, causing the workbook to stay open until it's closed manually, which is most likely the cause of your issue.

The code below will cancel the last scheduled time when the workbook closes. Code goes in the ThisWorkbook module.

VBA Code:
Option Explicit

Private Type TLocals
    ScheduledTime As Double         ' <<< storage for scheduled date & time
    Macro         As String         ' <<< storage for macro to be scheduled
End Type
Private this As TLocals

Private Sub Workbook_Open()
    ReSchedule
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ScheduleCancel
End Sub

Public Sub ReSchedule()
    With this
        .ScheduledTime = VBA.Now + VBA.TimeValue("00:10:00")
        .Macro = "ThisWorkbook.SaveThis"
        Excel.Application.OnTime .ScheduledTime, .Macro
    End With
End Sub

Public Sub ScheduleCancel()
    On Error Resume Next
    Excel.Application.OnTime EarliestTime:=this.ScheduledTime, Procedure:=this.Macro, Schedule:=False
End Sub

Public Sub SaveThis()
    Application.DisplayAlerts = False
    ThisWorkbook.Save
    Application.DisplayAlerts = True
    ReSchedule
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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