Determin if a workbook is already opened by another user.

BKoetting

New Member
Joined
Feb 18, 2003
Messages
3
I have a macro that updates several workbooks. I need to be able to determin if the workbook is already open. I'm looking for something like a Workbooks property that returns true or false value on the current state of the workbook.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Re: Determin if a workbook is already opened by another user

I did this once. Here's my code. See if you can modify it to work for you:

Code:
'   Open Invoice File 
    MyInvoiceFile = "W:\USERS\INVOICE #2002.xls"
    Set MyWorkBook = Workbooks.Open(MyInvoiceFile)

'   Check to see if file is already open
    If MyWorkBook.ReadOnly Then
        ActiveWorkbook.Close
        MsgBox "Cannot update Invoice Log, someone currently using file.  Please try again later."
        Exit Sub
    End If
 
Upvote 0
Re: Determin if a workbook is already opened by another user

Thanks for your help, the code worked perfectly.
 
Upvote 0
Re: Determin if a workbook is already opened by another user

What is the method to find out who has the workbook open? I need to update a content log with over a 100 people who can access it. It would be handy to be able to know who to contact if the automatic update fails.
 
Upvote 0
Re: Determin if a workbook is already opened by another user

MPW, did you ever get an answer to your question? I have the same question!
 
Upvote 0
Re: Determin if a workbook is already opened by another user

The ReadOnly method above works when a workbook is open, but also flags a closed readonly workbook, so take that into account if you use it. I'd still like to know if there's a way to return the user who has the workbook open to my script, so that I can send him an email or IM or something. I'm using Win 7 with office 2013.
 
Upvote 0
Re: Determin if a workbook is already opened by another user

I could determine if a file is in use with this:
Code:
        Ret = IsWorkBookOpen(Wherwithal & "\" & wkbkname)    
        If Ret = True Then
            MsgBox "The " & wkbkname & " is open." & vbCrLf & _
            "Please update it later."
            Exit Sub
        End If

Hope it helps.
 
Upvote 0
Re: Determin if a workbook is already opened by another user

...
Code:
        Ret = IsWorkBookOpen(Wherwithal & "\" & wkbkname)
...

Stumbled across this thread. Just a quick note to anyone reading it — IsWorkbookOpen() is not a built-in function. The return value of the function would depend on the code within it. Most versions of the IsWorkbookOpen() function (or sometimes the function is named WorkbookIsOpen or WorkbookOpen) posted online are a variation of a function John Walkenbach published decades ago and only check to see if a workbook is open within the active instance of Excel for the user running the macro.

@ billritz - if there is a way to ascertain the username of the person who has the workbook open using built-in properties of Excel or VBA, I've not seen it. One could create something in Excel, but it would not be native and would require a fair amount of work.
 
Last edited:
Upvote 0
Re: Determin if a workbook is already opened by another user

Thanks for the reply. I'm using the .readonly to see if it's open, but I like you never did find a way of getting the name that is put in under options to let the user know who the user is. We had some people who'd open a workbook and cover it with other windows and forget it was open.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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