View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Datasort Datasort is offline
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