Hi there,
See if the attached workbook does what you need.
It uses the following code which should be inserted into the "ThisWorkbook" VBA CodeModule of your workbook:
Option Explicit
Private Sub Workbook_Open()
Dim iYesNo As Integer
Dim wbk As Workbook
Windows(Me.Name).Visible = False
If Workbooks.Count > 1 Then
iYesNo = MsgBox("No other workbooks may be open while workbook """ & _
Me.Name & """ is open" & _
vbLf & vbLf & _
"Do you want to close ALL open workbooks?" & _
vbLf & _
"(Any changes to open workbooks will be saved " & _
"automatically before the workbooks are closed)", _
vbYesNo + vbQuestion, "Other workbooks are open")
If iYesNo = vbYes Then
For Each wbk In Workbooks
If Not wbk Is Me Then
wbk.Close SaveChanges:=True
End If
Next wbk
Windows(Me.Name).Visible = True
Me.Saved = True
Else: MsgBox "The workbook """ & Me.Name & """ will now be closed", _
vbInformation, "Application not available"
Me.Close SaveChanges:=False
End If
Else: Windows(Me.Name).Visible = True
Me.Saved = True
End If
End Sub
Hope this helps - please let me know how you get on.
Regards,
Greg M
Bookmarks