|
-
Jul 20th, 2006, 07:15 AM
#1
Thread Starter
Lively Member
[RESOLVED] Check for open workbooks
Hi
Is there any way I can check if a specific workbook, e.g. book1.xls, is open?
I've been trying to do something like this;
VB Code:
If book.xls exist then 'This is the line that bothers me!
'code
else
workbooks.add 'creating book1.xls
'code
end if
I know i've posted a smiliar question earlier, but hopefully by rephraising it someone can help me
Thanx
Nick
-
Jul 20th, 2006, 07:42 AM
#2
Re: Check for open workbooks
VB Code:
Sub nextsub()
Dim b As Workbook
For Each b In Application.Workbooks
If b.Name = "Full structre practice.xls" Then
b.Activate
Exit Sub
End If
Next
Workbooks.Open "Full structre practice.xls"
Exit Sub
here is the code you need, it checks all the open workbooks till it finds the one you want, then maces it the active one, if not open, opens it
pete
-
Jul 20th, 2006, 10:55 AM
#3
Re: Check for open workbooks
I think you would be much better off with a generic function that accepts a bookname as a paramater and returns whether or not that book is open.
Somethin like..
VB Code:
Function BookIsOpen(ByRef BookName As String) As Boolean
Dim wkbBook As Workbook
For Each wkbBook In Application.Workbooks
If wkbBook.Name = BookName Then
BookIsOpen = True
Exit Function
End If
Next wkbBook
End Function
Then your code would look like
VB Code:
If BookIsOpen("YourBooksName") Then
'code
Else
Workbooks.Add 'creating book1.xls
'code
End If
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|