LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default To check worksheets are open or not

Hi,

I need to check only once (not loop) whether particular sheet is already
opened or not. I would like to use If else condition based on above
mentioned sheet. How can i do this.

I have tried your code and found that even if the file is not there is
proceeds instead of going to endif.

Pl. help.

Regards

"Dave Ramage" wrote:

The most efficient way is to trap the resulting error and process
accordingly, e.g.

On Error Resume Next
Sheets("book7").Activate
If Err.Number = 9 then
Msgbox "book7 not found"
End If
On Error Goto 0

If this is not desired then you will have to loop through all sheets in the
active workbook to see if one of them is named "book7"

Function WorkSheetExists(strName as String) As Boolean
Dim w as Object

For Each w In ActiveWorkbook.Sheets
If w.Name = strName Then
WorkSheetExists = True
End If
Next w
End Function

Cheers,
Dave
"Vijay Kotian" wrote:

While working on various sheets some times i get a error message if the sheet
is not there i would like to check prior to activating it. Is there any
command available to check the sheets e.g. book7 or book9 etc.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to check is someone else has a workbook open Jim K.[_2_] Excel Discussion (Misc queries) 2 August 29th 08 04:32 PM
check for worksheets erlanr Excel Worksheet Functions 1 September 8th 07 01:34 AM
Check if a document is open AnthonyJ Excel Programming 3 September 29th 06 03:15 PM
Check if workbook open dkipping Excel Discussion (Misc queries) 4 May 24th 06 02:00 PM
check if file already is open Mats Nilsson Excel Programming 2 September 12th 05 09:30 AM


All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"