Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Checking to see if a sheet is open

Hi
normally no need to 'open' a sheet. Maybe post your relevant code for
analysis to avoid activate/select statements

--
Regards
Frank Kabel
Frankfurt, Germany


Ben H wrote:
Hi all! I need to check to see if a sheet is already open, and if it
isn't, then open it and hide it. I am doing this in an attempt to
speed up a program that is taking way too long since I open the sheet
then close it and repeat that about 30 times.

THanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Checking to see if a sheet is open

dim otherWkbk as workbook
dim Title as string

title = "something.xls" '<--better to include the extension, too!

set otherwkbk = nothing
on error resume next
set otherwkbk = workbooks(title)
on error goto 0

if otherwkbk is nothing then
set otherworkbook = workbooks.open(filename:="C:\All\Info\" & Title)
end if

Chip Pearson posted this:
http://google.com/groups?threadm=%23...GP11.p hx.gbl

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

Then, you can call it from code with a statement like

If IsWorkbookOpen(WBName:="Stats Manager.xls") = True Then
' do you thing
End If

This makes it easier to check lots of times.

Ben H wrote:

Application.DisplayAlerts = False

Work_Area = ActiveWindow.Name

ChDir "C:\All\Info\"
Workbooks.Open Filename:="C:\All\Info\" & Title & ""
ActiveWindow.Visible = False

Where Title is the name of the file I am opening. I want to check to see if
it has been open before and if not, open it. I also don't know how to close
all workbooks that aren't the main one.

Let me try this: I am running the code out of the file "Bob" and need to
access data in the file "John" and "Ben" muliply times. Currently I open
"John"/"Ben", grab the data then close it. I think leaving them open is
quicker but I don't know how to code it.

"Frank Kabel" wrote:

Hi
normally no need to 'open' a sheet. Maybe post your relevant code for
analysis to avoid activate/select statements

--
Regards
Frank Kabel
Frankfurt, Germany


Ben H wrote:
Hi all! I need to check to see if a sheet is already open, and if it
isn't, then open it and hide it. I am doing this in an attempt to
speed up a program that is taking way too long since I open the sheet
then close it and repeat that about 30 times.

THanks!




--

Dave Peterson

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
Checking for Open Files Marston Excel Programming 2 August 16th 04 04:01 PM
Checking for open workbook... Squid[_2_] Excel Programming 7 February 28th 04 01:16 AM
Checking to see if a Workbook is Open Todd Huttenstine[_3_] Excel Programming 4 December 25th 03 11:55 PM
Checking if workbook is open Jesse[_4_] Excel Programming 6 December 11th 03 11:17 PM
Checking for Open Workbook sbharbour Excel Programming 6 August 28th 03 11:42 PM


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