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

If statement to check if workbook is OPEN?

10 views
Skip to first unread message

Michael

unread,
Feb 15, 2004, 1:45:13 PM2/15/04
to
Hi,

How do you use "If" statement to open a workbook, and if closed to open it?

Give an example please...

Thanks alot,
Mike

Bob Phillips

unread,
Feb 15, 2004, 1:58:40 PM2/15/04
to
Mike,

Try this

Dim oWb As Workbook

On Error Resume Next
Set oWb = Workbooks("SIP 2004.xls")
On Error GoTo 0
If oWb Is Nothing Then
Workbooks.Open Filename:="SIP 2004.xls"
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Michael" <mas_i...@yahoo.com> wrote in message
news:118f1485.04021...@posting.google.com...

Frank Kabel

unread,
Feb 15, 2004, 2:04:55 PM2/15/04
to
Hi
try the following UDF

Sub Function WB_Open(filename as string)
Dim WBook As Workbook
On Error Resume Next
Set WBook = Workbooks(filename)
On Error GoTo 0
If WBook Is Nothing Then
Workbooks.Open Filename:= filename
End If
end Sub


--
Regards
Frank Kabel
Frankfurt, Germany

Frank Kabel

unread,
Feb 15, 2004, 2:24:45 PM2/15/04
to
Sorry
was meant to be a procedure and not an UDF
Use
Sub Public WB_Open(filename as string)

Dim WBook As Workbook
On Error Resume Next
Set WBook = Workbooks(filename)
On Error GoTo 0
If WBook Is Nothing Then
Workbooks.Open Filename:= filename
End If
end Sub


--
Regards
Frank Kabel
Frankfurt, Germany

Frank Kabel wrote:
> Hi
> try the following UDF
>
> Sub Function WB_Open(filename as string)
> Dim WBook As Workbook
> On Error Resume Next
> Set WBook = Workbooks(filename)
> On Error GoTo 0
> If WBook Is Nothing Then
> Workbooks.Open Filename:= filename
> End If
> end Sub
>
>
>

Michael

unread,
Feb 16, 2004, 8:18:54 AM2/16/04
to
Thanks Frank very much...

Mike

"Frank Kabel" <frank...@freenet.de> wrote in message news:<eRQwfl$8DHA...@TK2MSFTNGP10.phx.gbl>...

0 new messages