I've got a Excel documents with macros with input and update forms for information, the document is used as a monthly database where you can run reports from as well.
The issue is that when using the document sometimes the input and update options are used at the same time causing information loss. Both the input and output save at the end of the macro to minimise the losses, but I was wondering if there is anyway of checking at runtime if there is a macro being use by another user and if so delay the next macro run until the other user is finished?
You and your colleagues can open and work on the same Excel workbook. This is called co-authoring. When you co-author, you can see each other's changes quickly—in a matter of seconds.
Click Review > Share Workbook. On the Editing tab, select the Allow changes by more than one user ... check box. On the Advanced tab, select the options that you want to use for tracking and updating changes, and then click OK.
By sharing an Excel file, you are giving other users access to the same document and allow them to make edits simultaneously, which saves you the trouble of keeping track of multiple versions.
There is one way I can think of. Logically it should work. However I have not tested it.
Code
Sub Sample()
Dim ws As Worksheet
ThisWorkbook.Save
Doevents
Set ws = ThisWorkbook.Sheets("HiddenSheetName")
If Len(Trim(ws.Range("A1").Value)) = 0 Then
ws.Range("A1").Value = "Macro Starts"
ThisWorkbook.Save
Doevents
'
'~~> Rest of your code goes here
'
ws.Range("A1").ClearContents
ThisWorkbook.Save
Doevents
Else
MsgBox "Please try after some time. There is a macro running... Blah Blah"
End If
End Sub
CAUTION: Once the code runs, you cannot undo the changes since the code save the file programatically. The changes are permanent. In a file which is not shared, you can undo by closing the file without saving and re-opening it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With