Opening an Excel File

S

Slim Slender

The following code tests whether a file is open on my computer and if
it isn't, it opens the file, and if it is already open, it tells me
that.

sub OpenMyFile()
dim myPath as string
dim myFile as string
dim wkbk as Workbook

myPath = "R:\share\ . . . Folder\"
myFile = "SomeFileName.xlsm"

set wlbk = Nothing
On Error Resume Next
set wkbk = Workbooks(myFile)
On Error GoTo 0

If wkbk Is Nothing Then
Set wkbk = Workbooks.Open(Filename:=myPath & myFile)
Else
MsgBox ("It's already open")
End If
End Sub

The problem is that the file is on a network drive and others can open
it. If someone else has it open, this routine will go ahead and open
in on my computer as (Read Only). I would prefer that it not do that
but instead give me the prompt that I would get if were to use to
navigate to it and try to open it. In that case there would be a
prompt telling who had it open and giving choices to open as Read Only
or Notifiy or Cancel. Can code to that effect be added to this
procedure?
 

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