check all the workbook names that are open if it isn't it opens it.
Printable View
check all the workbook names that are open if it isn't it opens it.
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:
Code: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
:)
Just another way to skin the cat :)
Code: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
I just want to show this:
http://www.vbaexpress.com/forum/showthread.php?t=87
I was looking for that before but couldn't find it!
:)
My bad. I mass-moved some stuff to the wrong place. :(