testing for workbook already open

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a macro that opens a form and workbook however I want to test to see
if the form is already opened by the user. This looks like it should work
but it doesn't like the line:
set wkb = GetObject.Openxxxxx

Public Sub openFile()


Const fName As String = "Book1.xls"
Const fPath As String = "Mac OS X:SSP Process:"

Dim wkb As Workbook

Set wkb = GetObject.Open(Filename:=fPath & fName)
If Err.Number <> 0 Then _
Set wkb = Workbooks.Open(Filename:=fPath & fName)
Err.Clear


End Sub


Thanks,
 
It should be something like this...

Public Sub openFile()

Const fName As String = "Book1.xls"
Const fPath As String = "Mac OS X:SSP Process:"

Dim wkb As Workbook

on error resume next
Set wkb = workbooks(fName)
on error goto 0
if wbk is nothing then _
Set wkb = Workbooks.Open(Filename:=fPath & fName)

End Sub
 
Sorry Typo wbk should be wkb...

Public Sub openFile()

Const fName As String = "Book1.xls"
Const fPath As String = "Mac OS X:SSP Process:"

Dim wkb As Workbook

on error resume next
Set wkb = workbooks(fName)
on error goto 0
if wkb is nothing then _
Set wkb = Workbooks.Open(Filename:=fPath & fName)

End Sub
 
That is the thing about computers. Simple is complicated and complicated is
simple. The mark of good spreadsheets and good code is that it looks simple...

As a complete aside you are really getting the hang of this. You are rapidly
making the leap from recorded code full of selects and other extraneous bits
to simple well strutured code dealing with the underlying object of Excel.
Keep up the good work.
 
Back
Top