Shared Workbook Macro

pure vito

Board Regular
Joined
Oct 7, 2021
Messages
183
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I understand that macro's and shared documents don't really go hand in hand, below is a code that adds a note to every cell entry, with the username and a time stamp,
when I upload the document the macro stops working, is it possible to have this kind of macro run on a shared document? Thanks in advance.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   
    Dim oComment As Comment, cell As Range, strPrev As String

    If Not Intersect(Target, Columns("M:NM")) Is Nothing Then

        For Each cell In Intersect(Target, Columns("M:NM"))

            Set oComment = Nothing
            On Error Resume Next
                Set oComment = cell.Comment
            On Error GoTo 0

            If Not oComment Is Nothing Then
                strPrev = Mid(oComment.Text, InStr(oComment.Text, "Current value: ") + 15, 999)
                oComment.Text Text:=Format(Now, "mmm dd, yyyy  h:mm AM/PM")
                                   
                                   
            ElseIf Not IsEmpty(cell) Then
                cell.AddComment
                cell.Comment.Text Text:=Format(Now, "mmm dd, yyyy  h:mm AM/PM  ") & Application.UserName
                cell.Comment.Shape.Width = 150
                cell.Comment.Shape.Height = 35
                
            End If
        Next cell
    End If
   
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
What exactly do you mean by "upload the document"?
 
Upvote 0
What exactly do you mean by "upload the document"?
Hi Rory, the document has been created and then shared if that makes sense, it was only me using it before but now it needs to be a shared document
 
Upvote 0
How exactly are you sharing it? In any online version (eg embedded in Teams) VBA will not run.
 
Upvote 0
Thanks Rory, it's an online version I just read somewhere certain macros will run and I thought this might apply to the code above, are you aware of any way
of adding a time and date stamp to an edited cell of the online version similar to what the code does? and thanks for your time,
 
Upvote 0
In the online version you have to use Office Script, and I haven't even looked at those yet, I'm afraid. Hopefully someone else might jump in.
 
Upvote 0
Ok at least I know vba won't work now, that's great and as always thanks for your help Rory I'm always grateful to see your name in the comments section :cool:
 
Upvote 0

Forum statistics

Threads
1,223,990
Messages
6,175,817
Members
452,672
Latest member
missbanana

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