If statement to check if workbook is OPEN?

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hi,

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

Give an example please...

Thanks alot,
Mike
 
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)
 
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
 
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
 
Thanks Frank very much...

Mike

Frank Kabel said:
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
 
Back
Top