PDA

View Full Version : Solved: Run code if workbook abc.xls is open



khalid79m
09-24-2008, 03:59 AM
Private Sub M()
Environ$ ("username")
Dim sID As String
sID = LCase(Environ$("username"))
If sID = "046439" Then

Application.EnableEvents = False
Application.DisplayAlerts = False

Else

Application.EnableEvents = True
Application.DisplayAlerts = True

End If
End Sub

I currently use this code if i am logged on , it stops the enablevents and alerts if i have opend the document, if someone else opens it the enablevents & Display alerts is true.

I need this code to only work if the workbook "abc.xls" is open in the background rather than who opens it.

can anyone help

Bob Phillips
09-24-2008, 04:10 AM
Private Sub M()
Dim wb As Workbook

On Error Resume Next
Set wb = Workbooks("abc.xls")
On Error GoTo 0

If Not wb Is Nothing Then

Application.EnableEvents = False
Application.DisplayAlerts = False

Else

Application.EnableEvents = True
Application.DisplayAlerts = True
End If
End Sub

khalid79m
10-23-2008, 04:30 AM
thanks works great