简体   繁体   中英

How can I get list of users using specific shared workbook?

I'm using shared workbook. There is a code that undo share for the WB, updates data in the sheets and then share the WB again. If there are users connected to this WB, they will loose the ability to save on the WB and excel will ask the them to save the WB in different name.

My question is how can I get the list of the users that are currently using the WB?

This way I can set a msgbox that alert upon there are users using the WB and keep the WB shared for all.

Thanks

Try to use UserStatus Property [Excel 2003 VBA Language Reference] :

Returns a 1-based, two-dimensional array that provides information about each user who has the workbook open as a shared list. The first element of the second dimension is the name of the user, the second element is the date and time when the user last opened the workbook, and the third element is a number indicating the type of list (1 indicates exclusive, and 2 indicates shared). Read-only Variant.

Example

This example creates a new workbook and inserts into it information about all users who have the active workbook open as a shared list.

users = ActiveWorkbook.UserStatus
With Workbooks.Add.Sheets(1)
    For row = 1 To UBound(users, 1)
        .Cells(row, 1) = users(row, 1)
        .Cells(row, 2) = users(row, 2)
        Select Case users(row, 3)
            Case 1
                .Cells(row, 3).Value = "Exclusive"
            Case 2
                .Cells(row, 3).Value = "Shared"
        End Select
    Next
End With
Sub getListUsingUsers()
    Users = ActiveWorkbook.UserStatus
    MsgBox "Total Users using the current WorkBook: " & UBound(Users)
End Sub

This code give me the msgbox with the amount of users connected to the WB.

Thanks @duDE

Wow. How about just going to MenuBar-Review=>Share Workbook=>Editing tab and see all users with WB open

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM