ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Identify if another user has spreadsheet open - in VBA (https://www.excelbanter.com/excel-programming/284890-identify-if-another-user-has-spreadsheet-open-vba.html)

gp

Identify if another user has spreadsheet open - in VBA
 
I would like to run a vba routine if a particular workbook
is not currently in use by someone else. I cannot find
any function ore code that will identify if the book is in
use or not.

Harald Staff

Identify if another user has spreadsheet open - in VBA
 
Hi

You have to open it by code. From there, if it's Readonly then someone else has its
exclusive rights. Or, if you are lucky, the WriteReservedBy property will return the
username of this exclusive user.

I believe that a faster and safer solution is to have a small macro in that particular
book that logs to an available textfile or whatever when and who is opening/closing it.
Then you don't have to touch the file to find this information.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"gp" wrote in message
...
I would like to run a vba routine if a particular workbook
is not currently in use by someone else. I cannot find
any function ore code that will identify if the book is in
use or not.




Ricky M. Medley

Identify if another user has spreadsheet open - in VBA
 
Harald wrote:
You have to open it by code.<<snip


Not necessarily, you could place code on ThisWorkbook code page...

Private Sub Workbook_Open()
If ActiveWorkbook.ReadOnly = False Then 'Means workbook is not read only
'<call your code/function/sub here
End if
End Sub

regards
ricky

Harald Staff

Identify if another user has spreadsheet open - in VBA
 
"Ricky M. Medley" wrote in message
...

You have to open it by code.<<snip


Not necessarily, you could place code on ThisWorkbook code page...


Well yes, sorry. You could of course open it manually and then have some code running. You
could even open it manually, read the prompt "This file is in use by Harry Callahan. Do
you want to open it Readonly ? Do you feel lucky today ?" and then type "Harry has it"
into a Word macro. Point is, you have to actually open the file to get any information.
And the lady said VBA. But you're right.

Best wishes Harald
Followup to newsgroup only please.





All times are GMT +1. The time now is 12:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com