Consulting

Results 1 to 3 of 3

Thread: Solved: Run code if workbook abc.xls is open

  1. #1

    Red face Solved: Run code if workbook abc.xls is open

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    thanks works great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •