Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Simpl Q about the Workbook Object

Try the following

Public Function IsWorkbookOpen(ByVal sWBName$) As Boolean
Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks(sWBName)
IsWorkbookOpen = (Err = 0)
On Error GoTo 0
End Function

Note that this will only report on those workbooks that are open in the same
instance of the excel application. I am using Excel 2003 and in this version
if you have Book1.xls and Book2.xls open in one instance of Excel and
Book3.xls open in the other instance of Excel then the function written say
in the Module in Book1.xls will return true when called like this
Debug.print IsWorkbookOpen("Book1.xls")
Debug.print IsWorkbookOpen("Book2.xls")

but will return False when called for Book3.xls like this
Debug.Print IsWorkbookOpen("Book3.xls")


"Amanda V" wrote:

Hey All,

I need a simple way to check if my ReportBook (Workbook Object) is
Open.
Right now users hit a button to populate some data, but If the user
selects new data for population and hits the button, I want to check
that the RecordBook is not currently "in-use" or "assigned" to another
Excel Workbook (namely the previous one).

As well, I would like for when the user manually closes Excel, that the
ReportBook is also 'closed' 'realeased' or whatever the proper protocol
should be for not leaving a whole bunch of objects drifting around
without closure ;) This way, when the user hits the above mentioned
button, the program recognizes the ReportBook Object as not assigned to
anything (or available for use).

Thanks!

Amanda


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
Inserting an Object from a different workbook - please help Nick Excel Discussion (Misc queries) 0 February 23rd 10 12:04 PM
Excel pastes as object into new workbook Bert Excel Discussion (Misc queries) 2 December 21st 06 07:22 PM
Workbook and Window object question Frederick Chow Excel Programming 6 December 24th 05 12:58 PM
Open workbook object cottage6 Excel Programming 0 December 6th 04 02:35 PM
Proper syntax to Set a Workbook Object? Rick Stanford Excel Programming 2 September 13th 03 07:15 PM


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