PC Review


Reply
Thread Tools Rate Thread

checking if a sheet exists

 
 
greg
Guest
Posts: n/a
 
      9th Jul 2008
Is there a good way of checking if a sheet exists?
Besides doing this
excel.ActiveWorkbook.Sheets("foo").name
and catching the error that is thrown.


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      9th Jul 2008
I think that's the best way I've seen.

But if you don't like, you could loop through all the sheets to see if any of
the names match the name you're looking for. That seems less efficient than
what you suggest.

greg wrote:
>
> Is there a good way of checking if a sheet exists?
> Besides doing this
> excel.ActiveWorkbook.Sheets("foo").name
> and catching the error that is thrown.


--

Dave Peterson
 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      9th Jul 2008
looping through the sheets and checking each name



--
Regards,
Tom Ogilvy


"greg" wrote:

> Is there a good way of checking if a sheet exists?
> Besides doing this
> excel.ActiveWorkbook.Sheets("foo").name
> and catching the error that is thrown.
>
>
>

 
Reply With Quote
 
Gary Brown
Guest
Posts: n/a
 
      9th Jul 2008
That is the best way as far as I can see....
'/===============================/
Public Function FileExists(strFileName As String) _
As Boolean
FileExists = False
If Dir(strFileName) <> "" Then
FileExists = True
End If
End Function
'/===============================/

--
Hope this helps.
If this post was helpfull, please remember to click on the ''''YES''''
button at the bottom of the screen.
Thanks,
Gary Brown


"greg" wrote:

> Is there a good way of checking if a sheet exists?
> Besides doing this
> excel.ActiveWorkbook.Sheets("foo").name
> and catching the error that is thrown.
>
>
>

 
Reply With Quote
 
Gary Brown
Guest
Posts: n/a
 
      9th Jul 2008
oops read it wrong. You said sheet, I thought file :O<
'==============================================
Public Function SheetExists(sName) As Boolean
' Returns TRUE if sheet exists in the active workbook
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sName)
If Err = 0 Then SheetExists = True _
Else SheetExists = False
End Function
'==============================================

--
Hope this helps.
If this post was helpfull, please remember to click on the ''''YES''''
button at the bottom of the screen.
Thanks,
Gary Brown


"Gary Brown" wrote:

> That is the best way as far as I can see....
> '/===============================/
> Public Function FileExists(strFileName As String) _
> As Boolean
> FileExists = False
> If Dir(strFileName) <> "" Then
> FileExists = True
> End If
> End Function
> '/===============================/
>
> --
> Hope this helps.
> If this post was helpfull, please remember to click on the ''''YES''''
> button at the bottom of the screen.
> Thanks,
> Gary Brown
>
>
> "greg" wrote:
>
> > Is there a good way of checking if a sheet exists?
> > Besides doing this
> > excel.ActiveWorkbook.Sheets("foo").name
> > and catching the error that is thrown.
> >
> >
> >

 
Reply With Quote
 
Charlie
Guest
Posts: n/a
 
      9th Jul 2008
That's how I do it but you could do something like:

Public Function SheetExists(SheetName As String) As Boolean
'
Dim Sheet As Worksheet
'
For Each Sheet In ThisWorkbook.Worksheets
If Sheet.Name = SheetName Then
SheetExists = Yes
Exit Function
End If
Next Sheet
'
End Function


"greg" wrote:

> Is there a good way of checking if a sheet exists?
> Besides doing this
> excel.ActiveWorkbook.Sheets("foo").name
> and catching the error that is thrown.
>
>
>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      9th Jul 2008
There are a few ways on this page
http://www.rondebruin.nl/exist.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"greg" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Is there a good way of checking if a sheet exists?
> Besides doing this
> excel.ActiveWorkbook.Sheets("foo").name
> and catching the error that is thrown.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking if a Chart Exists on a Sheet Keith Wilby Microsoft Excel Programming 6 30th Mar 2007 03:06 PM
Checking if the sheet already exists =?Utf-8?B?R3JlZw==?= Microsoft Excel Programming 3 9th Nov 2006 01:25 AM
Checking if Sheet Exists? brett.kaplan@gmail.com Microsoft Excel Misc 5 1st Sep 2006 03:27 PM
checking if an url exists Aldo Microsoft Excel Programming 2 9th Oct 2005 10:20 PM
checking to see if DDL value exists Darrel Microsoft ASP .NET 4 10th Dec 2004 03:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:50 AM.