RemoveUser Method of Workbook Object VBA

RemoveUser Workbook is used to remove access to the user from the shared workbook. We are using RemoveUser method of workbook object to remove access from the shared workbook.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


Why we need to RemoveUser from the Shared Workbook?

Sometimes we need to removeuser from the shared workbook access. For example an employee has moved from the organization that time we may need to remove access to employee form shared workbook access.

VBA RemoveUser Workbook – Syntax

Here is the syntax to remove user from the shared workbook using VBA.

Workbooks(“Your Workbook Name”).RemoveUser(Index As Long)

Where Index is the mandatory argument. It represents the index of user to remove access from the shared workbook.
In the above syntax we are using ‘RemoveUser’ method of workbook object to remove user to access the workbook.

VBA RemoveUser Workbook:Example 1

Please find the below example, It will show you how to remove user from the shared workbook.

Sub Remove_User1()
Dim UsrList()
UsrList = ThisWorkbook.UserStatus
If UBound(UsrList) > 1 Then
ThisWorkbook.RemoveUser (2)
End If
End Sub

Explanation: In the above example we are removing the second user from the available user access list of workbook.

VBA RemoveUser Workbook:Example 2

Sub Remove_User2()
Dim UsrList()
UsrList = ThisWorkbook.UserStatus
For i = 1 To UBound(UsrList)
ThisWorkbook.RemoveUser (i)
Next
End Sub

Explanation: In the above example we are removing all the available user access from the workbook.
Please follow the below steps to execute the VBA code to save the excel file.
Step 1: Open any existing Excel workbook.
Step 2: Press Alt+F11 – This will open the VBA Editor.
Step 3: Insert a code module from then insert menu.
Step 4: Copy the above code and paste in the code module which have inserted in the above step.
Step 5: Now removed users cannot access to the shared workbook.
Step 6: Now press F5 to execute the code.

LIMITED TIME OFFER

Leave A Comment


Related pages


vba hide columnsvba excel sample projectsmake drop down list in excel 2007sql ddl dml dcl tcl commands pdfvbs messageboxexcel offset function examplesvba range clearexcel vba sql serverunhide top rows in excelaccess vba if then elseexcel vba removevba integerexcel getopenfilenameexcel 2010 lookup functionexcel vba create xmlformula sumif excelexcel remove duplicate linesexcel vba sort rangevba create worksheethow to put a tick box in excelvb nested ifhow to put columns in exceldml queryms access export to excel vbavba combobox indexexcel if isna vlookupapplication.inputboxdatediff excelshortcuts keys for excelxls macrooffset function in excelexcel sheet name in cellvba excel dashboardappend to a text filetable pivot excelmsgbox vbokonlymatch function in excel vbavba open file for inputexcel vba if statementshow to create a drop down menu in excel 2007financial analyst interview questions and answers pdfeasy vlookup stepsautofilter macrogenerate graph in excelloop vba exceldefinition of vlookup functionhow to insert a hyperlink in excelworksheet function vbaword dashboard templatewith selection vbavba loop syntaxcell format vbavbscript excel tutoriallookup function excel 2007formula in excel vbaworkbook activatehow to change row to column in excelenable macros vbadashboard examples in excelinterior vbaaria charts 2010excel vba listbox rowsourcepassword protected excel sheetexcel merge worksheetsinsert check mark in excel 2007excel how to insert rowexcel function offsetlookup in excelexcel function hyperlinkvba string manipulationmsg in vba