If a Workbook is already open?
I use this function to test if a file is open before I let the user try to
open it.
Function WorkbookIsOpen(wbname) As Boolean
' Returns TRUE if the workbook is open
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else WorkbookIsOpen = False
End Function
I call that function with this statement:
SummaryFileOpen = WorkbookIsOpen(summaryFileName)
and declare 'summaryFileName' this way
Private Const summaryFileName As String = "Summary.xls"
I got that function from the JW book on Excel Power Programming with VBA.
KL
"Mick" wrote in message
...
Hi
I have a macro that opens a workbook for the user to modify. However, I
need to stop the user from opening the workbook for a second time. I have
used the normal read only attribute which works to a degree, but if the
user chooses "No" I get an error in the macro. Also I don't want the user
to be able to say "Yes" and loose all the modifications made by opening
the workbook again.
--
Kind Regards
Mick
|