Link to home
Start Free TrialLog in
Avatar of AL_XResearch
AL_XResearchFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel - How to restrict 'Accept / Reject' to one user

I want to be able to allow sharing on a workbook and track changes but I don't want to allow just any user to accept or reject changes.

Ideally this would be without any VBA but if there is no other way ...

Unfortunately I have never worked with shared workbooks.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Select Case Application.UserName
    Case "Martin Liss", "Barack Obama"
        ' allow
End Select

Open in new window

You can also use Environ$("Username") in the same way.
Avatar of AL_XResearch

ASKER

Hi Martin.

Thanks for the quick response but I am sorry to say I don't understand. Of course that select statement would allow you to check if the current user is allowed but how do you link you code to the 'Accept or Reject' event ?

I can come up with all the VBA validation and testing - all I need to know is how to intercept and apply as needed.

As I say I am ideally looking for a non-VBA solution but if VBA is required then I need to know how to intercept or override the 'another user has made a change - which one wins ?' event.
I don't (and can't) work with shared workbooks but in order to do what you want I think you'll need to modify the ribbon for those who you don't want doing it - if that's possible in a shared workbook.

Ron De Bruin has articles on modifying the ribbon.
Here's how you'd get the submenu IDs. (From a comment from him I found on the web.)
Sub GetAll_Submenu_Ids()
Dim ctrl As Object
For Each ctrl In CommandBars("Tools") _
.Controls("Track Changes").Controls
MsgBox ctrl.Caption & Chr(13) & ctrl.ID
Next ctrl
End Sub

Open in new window

Martin: That is certainly one way of doing it but I always avoid working with CommandBar objects - simply because a) we don't know for how long MS will support them (in light of the move to ribbon controls) and b) I am never comfortable about mixing Ribbon and CommandBar work as I can't be sure how much 'internal application conflict' there is between these two rival but very different methods of control.
To put my question another way: what is the best VBA way to automatically accept or reject the current user's changes seamlessly ?
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Application.UserName
    Case "Martin Liss", "Barack Obama"
        ' allow
    Case Else
        ' reject
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
End Select
End Sub

Open in new window

Hi Martin,

Yes that is the simple part of how to distinguish the user and who is allowed - what I want is the code that goes in the section you have marked " ' allow "

By the same taken I need to know how to determine if there changes outstanding for more than one user.
Please describe the "allow" process.
Well in your code sample of the select block to decide what to do based on the username you have a comment for the ''Allow" case statement - what is the code that would go in there ?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial