PDA

View Full Version : Solved: How do I Check if a workbook is opened??



Daxton A.
06-09-2004, 09:16 AM
check all the workbook names that are open if it isn't it opens it.

mark007
06-09-2004, 09:25 AM
If I read this right you want to check if a specific workbook is open and if not to open it?

If so then use the following:


Dim wb As Workbook
On Error Resume Next
Set wb=application.workbooks("WorkbookName.xls")
On Error Goto 0 'now reset error handling
If wb Is Nothing Then
application.workbooks.open("Path to file\WorkbookName.xls")
end if


:)

Tommy
06-09-2004, 10:38 AM
Just another way to skin the cat :)


Sub FindWrkBk(PathToWorkbook As String, WrkBook As String)
Dim IsThere As Boolean
Dim Wrkbk As Workbook
IsThere = False
For Each Wrkbk In Workbooks
If Wrkbk.Name = WrkBook Then
IsThere = True
End If
Next
If Not IsThere Then
Application.Workbooks.Open PathToWorkbook & "\" & WrkBook
End If
End Sub
Sub does()
FindWrkBk "C:\WINDOWS\Desktop\stuff", "class.xls"
End Sub

Anne Troy
06-09-2004, 12:50 PM
I just want to show this:

http://www.vbaexpress.com/forum/showthread.php?t=87

mark007
06-09-2004, 02:44 PM
I was looking for that before but couldn't find it!

:)

Anne Troy
06-09-2004, 03:15 PM
My bad. I mass-moved some stuff to the wrong place. :(