ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test to see if a workbook is open (https://www.excelbanter.com/excel-programming/323433-test-see-if-workbook-open.html)

Alex St-Pierre

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

Dick Kusleika[_4_]

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




Datasort

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


Bob Phillips[_6_]

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





All times are GMT +1. The time now is 09:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com