Exclusive Access

S

Stephen sjw_ost

One more question :)

How can I check to see if my workbook is already open exclusive?

I am using this code to set my workbook exclusive.

Application.DisplayAlerts = False
'
Windows("JAX_PassCounts_v0.9.8.xls").Activate
ActiveWorkbook.ExclusiveAccess
Do
On Error Resume Next
ActiveWorkbook.Save
Loop Until ActiveWorkbook.Saved = True
'
Application.DisplayAlerts = True

How can I write in here that if the file is already exclusive to exit the sub?
I tried somthing like

If ActiveWorkbook.ExclusiveAccess = True then
Exit Sub
End If

But this did not work, it tried to set the file exclusive and errored out.

Thanks for any help!
 
J

JLGWhiz

This was in the VBA help file:

If ActiveWorkbook.MultiUserEditing Then
ActiveWorkbook.ExclusiveAccess
End If
 
J

JLGWhiz

You would need to add a line to exit the sub if it is already exclusive
access:

If ActiveWorkbook.MultiUserEditing Then
ActiveWorkbook.ExclusiveAccess
Else
Exit Sub
End If
 
S

Stephen sjw_ost

Makes sense to check for Multiuser first. Thank you very much for the reply.
I understand it now as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top