Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Does worksheet exist

Hi

Here'sthe background. I have a master workbook with a user defined function
that will fetch values from other open workbooks. The UDF will loop over
dynamically built referernce to particular cells and return a sum. This is
something I made for someone who needed to build a report based on the
values from these workbooks. The workbooks themselves have been generated by
some third party software. and contain financial information. This UDF works
very well and has saved lots of time by collecting this information
automatically. Previosly, the user had to do this error prone job manually
which took several hours

The problem is that there will be an error if the worksheet doesn't exist.
Fro some reason, it seems as if certain worksheets within the workbook won't
be generated.
I have already tested that the workbook is open.

How can I check if a worksheet exists in a different workbook from a UDF?? I
already know the name of the workbook where the worksheet is supposed to be.

Thanks in advance,
Fredrik


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 300
Default Does worksheet exist

Fredrik Wahlgren wrote:

How can I check if a worksheet exists in a different workbook from a UDF?? I
already know the name of the workbook where the worksheet is supposed to be.


I use the following, though it expects the workbook to be tested to be the
active one. Your macro can do this. Or modify the below. Don.

Function IsWorksheetOpen(worksheetname As String) As Boolean
' function tests for worksheet by that name exists

Dim shName As Worksheet

IsWorksheetOpen = False
For Each shName In Application.Worksheets
If shName.Name = worksheetname Then
IsWorksheetOpen = True
Exit Function
End If
Next shName

End Function

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Does worksheet exist

Fredrik,

Something borrowed from Chip Pearson 04/20/2003
In public.excel.programming
'--------------
Function WorksheetExists(WSName As String, _
Optional WB As Excel.Workbook = Nothing) As Boolean
On Error Resume Next
WorksheetExists = CBool(Len(IIf(WB Is Nothing, _
ThisWorkbook, WB).Worksheets(WSName).Name))
End Function
'-------------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Fredrik Wahlgren"
wrote in message
Hi
Here'sthe background. I have a master workbook with a user defined function
that will fetch values from other open workbooks. The UDF will loop over
dynamically built referernce to particular cells and return a sum. This is
something I made for someone who needed to build a report based on the
values from these workbooks. The workbooks themselves have been generated by
some third party software. and contain financial information. This UDF works
very well and has saved lots of time by collecting this information
automatically. Previosly, the user had to do this error prone job manually
which took several hours

The problem is that there will be an error if the worksheet doesn't exist.
Fro some reason, it seems as if certain worksheets within the workbook won't
be generated.
I have already tested that the workbook is open.
How can I check if a worksheet exists in a different workbook from a UDF?? I
already know the name of the workbook where the worksheet is supposed to be.
Thanks in advance,
Fredrik


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Does worksheet exist

Thank you Don and Jim

/Fredrik


Reply
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
Does a worksheet exist? Alan Excel Programming 1 May 3rd 06 11:04 PM
File opens as worksheet.xls:1 and worksheet.xls:2. Only one exist Dave the wave[_2_] Excel Programming 5 January 30th 06 11:28 PM
Does a worksheet exist? papa jonah Excel Programming 2 January 5th 06 06:20 PM
Does a worksheet exist Kaval[_2_] Excel Programming 3 May 31st 04 07:21 AM
Does worksheet exist Robert S Excel Programming 3 May 18th 04 07:59 PM


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

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"