![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 4
|
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 |
|
New Member
Join Date: Feb 2002
Location: Birmingham
Posts: 13
|
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|