Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Test to see if a workbook is open

Hello,
I would like to make a test before opening a file to see if there is a
workbook (same name) already opened.
if( workbook test.xls is open) then
msgbox("You must close the file first")
exit sub
end if
workbook.Open "C:\test.xls"
Thanks,
Alex
--
Alex St-Pierre
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Test to see if a workbook is open

Alex

http://www.dicks-blog.com/archives/2...rkbook-exists/

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Alex St-Pierre wrote:
Hello,
I would like to make a test before opening a file to see if there is a
workbook (same name) already opened.
if( workbook test.xls is open) then
msgbox("You must close the file first")
exit sub
end if
workbook.Open "C:\test.xls"
Thanks,
Alex



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Test to see if a workbook is open

Alex,

Try this:

Function TestForOpenWorkBook(strFileName As String) As Boolean
Dim objWorkBook As Workbook
ErrorCleanUp:

TestForOpenWorkBook = False

For Each objWorkBook In Application.Workbooks
If UCase(objWorkBook.Name) = strFileName Then
TestForOpenWorkBook = True
Exit Function
End If '**** Workbook open

Next '*** Loop thru workbooks

Exit Function

ErrorModule:

msgbox err.desciption
Resume ErrorCleanUp

End Function

Regards,

Stewart

"Alex St-Pierre" wrote:

Hello,
I would like to make a test before opening a file to see if there is a
workbook (same name) already opened.
if( workbook test.xls is open) then
msgbox("You must close the file first")
exit sub
end if
workbook.Open "C:\test.xls"
Thanks,
Alex
--
Alex St-Pierre

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Test to see if a workbook is open


On Error Resume Next
Set oWb = Workbooks("test.xls")
On Error Goto 0
If Not oWb Is Nothing Then
msgbox("You must close the file first")
exit sub
end if
workbook.Open "C:\test.xls"


--

HTH

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


"Alex St-Pierre" wrote in message
...
Hello,
I would like to make a test before opening a file to see if there is a
workbook (same name) already opened.
if( workbook test.xls is open) then
msgbox("You must close the file first")
exit sub
end if
workbook.Open "C:\test.xls"
Thanks,
Alex
--
Alex St-Pierre



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
Test to see if a workbook is open Brettjg Excel Discussion (Misc queries) 1 March 5th 07 09:26 AM
Test for Open File Aaron Excel Programming 6 January 6th 05 12:37 PM
Test if a workbook is open already Kieran1028[_17_] Excel Programming 7 November 22nd 04 08:13 PM
Test that a workbook is open Gef[_2_] Excel Programming 2 April 6th 04 11:17 AM
test for workbook open Rich C Excel Programming 1 March 1st 04 02:52 PM


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

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

About Us

"It's about Microsoft Excel"