|
-
Apr 20th, 2006, 01:41 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Is the sheet exist???
Hi Guys,
I'm looking for a macro or built-in fonction that can tell me, by the sheet name, if a sheet already exist in a workbook.
Excel 2003, VBA macro.
Thanks
-
Apr 20th, 2006, 01:45 PM
#2
Re: Is the sheet exist???
VB Code:
Function SheetExists(ByVal BookName As String, ByVal SheetName As String) As Boolean
Dim wksSheet As Worksheet
Dim bTemp As Boolean
For Each wksSheet In Workbooks(BookName).Worksheets
If wksSheet.Name = SheetName Then
bTemp = True
Exit For
End If
Next wksSheet
SheetExists = bTemp
End Function
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Apr 20th, 2006, 01:51 PM
#3
Thread Starter
Addicted Member
-
Apr 20th, 2006, 01:54 PM
#4
Re: Is the sheet exist???
Good, because I couldn't have done much better.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Apr 20th, 2006, 02:12 PM
#5
Re: Is the sheet exist???
Good, because I couldn't have done much better.
I lied...
You could also check to see of the workbook exists first...
VB Code:
Function SheetExists(ByVal BookName As String, ByVal SheetName As String) As Boolean
Dim wkbBook As Workbook
Dim wksSheet As Worksheet
Dim bTemp As Boolean
For Each wkbBook In Application.Workbooks
If wkbBook.Name = BookName Then
For Each wksSheet In wkbBook.Worksheets
If wksSheet.Name = SheetName Then
bTemp = True
Exit For
End If
Next wksSheet
End If
If bTemp Then Exit For
Next wkbBook
SheetExists = bTemp
End Function
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Apr 20th, 2006, 02:28 PM
#6
Thread Starter
Addicted Member
Re: [RESOLVED] Is the sheet exist???
Thanks...
but just before I check if the sheet exists I'm opening the workbook.
So I would have trapped the error before
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
|