Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opening an Excel File

6 views
Skip to first unread message

Slim Slender

unread,
May 22, 2012, 7:47:28 PM5/22/12
to
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?
0 new messages