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

Hi

I have built a user defined function which will reference a cell in an
external workbook. The idea is to make it easier to consolidate data into a
master sheet. The workbooks that I reference are created by another
application. Every month, a series of workbooks will be generated and the
idea is that the user only needs to tweak a few values in order to get the
data to the master sheet.

I may end up with something like this: '[05-000090-00_200512.xls]Subtask
#1'!$E$4
Before I evaluate this expression, I would like to know whether the workbook
05-000090-00_200512.xls is open

Since this is a UDF, I dont think I can do something like
Set wb = Application.Workbooks("05-000090-00_200512").Activate

How can I test whether the workbook is open?

/Fredrik


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Is worksheet open

Fredrik,

Here is a simple function to test it

Function IsOpen(FileName As String) As Boolean
On Error Resume Next
IsOpen = CBool(Len(Workbooks(FileName).Name))
End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Fredrik Wahlgren" wrote in message
...
Hi

I have built a user defined function which will reference a cell in an
external workbook. The idea is to make it easier to consolidate data into

a
master sheet. The workbooks that I reference are created by another
application. Every month, a series of workbooks will be generated and the
idea is that the user only needs to tweak a few values in order to get the
data to the master sheet.

I may end up with something like this: '[05-000090-00_200512.xls]Subtask
#1'!$E$4
Before I evaluate this expression, I would like to know whether the

workbook
05-000090-00_200512.xls is open

Since this is a UDF, I dont think I can do something like
Set wb = Application.Workbooks("05-000090-00_200512").Activate

How can I test whether the workbook is open?

/Fredrik




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Is worksheet open

One way (with no thought about checking the existence of the worksheet!):

Option Explicit
Function myFunction() As Variant

Dim testWkbk As Workbook

Set testWkbk = Nothing
On Error Resume Next
Set testWkbk = Workbooks("test.xls")
On Error GoTo 0

If testWkbk Is Nothing Then
myFunction = CVErr(xlErrRef)
Else
myFunction = testWkbk.Worksheets("Subtask #1").Range("e1").Value
End If

End Function

John Walkenbach shows some techniques for retrieving values from a closed
workbook:
http://j-walk.com/ss/excel/eee/eee009.txt

Fredrik Wahlgren wrote:

Hi

I have built a user defined function which will reference a cell in an
external workbook. The idea is to make it easier to consolidate data into a
master sheet. The workbooks that I reference are created by another
application. Every month, a series of workbooks will be generated and the
idea is that the user only needs to tweak a few values in order to get the
data to the master sheet.

I may end up with something like this: '[05-000090-00_200512.xls]Subtask
#1'!$E$4
Before I evaluate this expression, I would like to know whether the workbook
05-000090-00_200512.xls is open

Since this is a UDF, I dont think I can do something like
Set wb = Application.Workbooks("05-000090-00_200512").Activate

How can I test whether the workbook is open?

/Fredrik


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default Is worksheet open

Bob and Dave, Thank you

/Fredrik


"Fredrik Wahlgren" wrote in message
...
Hi

I have built a user defined function which will reference a cell in an
external workbook. The idea is to make it easier to consolidate data into

a
master sheet. The workbooks that I reference are created by another
application. Every month, a series of workbooks will be generated and the
idea is that the user only needs to tweak a few values in order to get the
data to the master sheet.

I may end up with something like this: '[05-000090-00_200512.xls]Subtask
#1'!$E$4
Before I evaluate this expression, I would like to know whether the

workbook
05-000090-00_200512.xls is open

Since this is a UDF, I dont think I can do something like
Set wb = Application.Workbooks("05-000090-00_200512").Activate

How can I test whether the workbook is open?

/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
Excel 2007, Automatically open new worksheet on open. jkmyoung Excel Discussion (Misc queries) 4 March 29th 10 04:36 PM
My desktop worksheet shortcut will not open the Excel Worksheet Steve09 Excel Discussion (Misc queries) 2 September 17th 09 04:33 PM
How do I get a blank worksheet to open up when I open Excel? Art@ISCO Setting up and Configuration of Excel 0 July 17th 07 01:30 PM
'Save current worksheet'; 'Open next worksheet' - two command buttons englishmustard Excel Discussion (Misc queries) 1 April 7th 06 12:54 PM
How do I get my personal macro worksheet to open whenever I open . Claudia_R Excel Discussion (Misc queries) 3 December 9th 04 11:59 PM


All times are GMT +1. The time now is 12:01 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"