Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

Is Name In Workbook

Option Explicit Public Function IsNameInWorkbook(ByVal Name As String) As Boolean    Dim X As String    Dim aRange As Range       Application.Volatile    On Error Resume Next    Set aRange = Application.Caller    Err.Clear        If aRange Is Nothing Then       X = ActiveWorkbook.Names(Name).Name    Else       X = aRange.Parent.Parent.Names(Name).Name    End If        If Err.Number = 0 Then IsNameInWorkbook = True End Function Public Sub TestName()   If IsNameInWorkbook(InputBox("What Name")) Then     MsgBox "Name exists"   Else     MsgBox "Name does not exist"   End If End Sub