Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Auto_Close / Prohibit Close

  1. #1
    New Member
    Join Date
    Feb 2002
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I thought this code might prohibt the user from closing the workbook if there is not a range named "NOI", but it is not working. Can somebody help.

    Sub Auto_Close()

    For Each Name In ActiveWorkbook.Names
    If Name.Name <> "NOI" Then
    Workbook.Close = False
    End If
    Next

    End Sub

  2. #2
    New Member
    Join Date
    Feb 2002
    Location
    Birmingham
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim nm As Name
    On Error Resume Next

    Set nm = ThisWorkbook.Names("NOI")
    If nm Is Nothing Then
    Cancel = True
    End If

    End Sub

    I don't think you should use Name as a variable name as its a VBA keyword.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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