Identify if another user has spreadsheet open - in VBA

  • Thread starter Thread starter gp
  • Start date Start date
G

gp

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.
 
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.
 
Harald said:
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
 
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.
 
Back
Top