PC Review


Reply
Thread Tools Rate Thread

Detect if a Defined Name Exists

 
 
Rob
Guest
Posts: n/a
 
      14th Jan 2009
Hi. I was wondering if there was a way for a macro to detect if there was a
field name already in use for a workbook?

I already tried...
If Exist Workbooks("Export.xls").Names("DATA1") Then

As well as...
If Workbooks("Export.xls").Names("DATA1") = True Then


Thanks very much,
Rob
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      14th Jan 2009
Function NameExist(s As String) As Boolean
Dim n As Name
NameExist = False
If ActiveWorkbook.Names.Count = 0 Then Exit Function
For Each n In ActiveWorkbook.Names
If s = n.Name Then
NameExist = True
Exit Function
End If
Next
End Function


--
Gary''s Student - gsnu200826


"Rob" wrote:

> Hi. I was wondering if there was a way for a macro to detect if there was a
> field name already in use for a workbook?
>
> I already tried...
> If Exist Workbooks("Export.xls").Names("DATA1") Then
>
> As well as...
> If Workbooks("Export.xls").Names("DATA1") = True Then
>
>
> Thanks very much,
> Rob

 
Reply With Quote
 
Jarek Kujawa
Guest
Posts: n/a
 
      14th Jan 2009
adjust "sth" name to suit yr needs

Sub cus2()
Dim nom As Name

For Each nom In ActiveWorkbook.Names
If nom.Name = "sth" Then
MsgBox "Name 'sth' exists in this workbook"
End If
Next nom

End Sub

On 14 Sty, 14:23, Rob <R...@discussions.microsoft.com> wrote:
> Hi. *I was wondering if there was a way for a macro to detect if there was a
> field name already in use for a workbook?
>
> I already tried...
> If Exist Workbooks("Export.xls").Names("DATA1") Then
>
> As well as...
> If Workbooks("Export.xls").Names("DATA1") = True Then
>
> Thanks very much,
> Rob


 
Reply With Quote
 
Rob
Guest
Posts: n/a
 
      14th Jan 2009
Thank You Very Much! That Worked Perfectly!

Cheers.


"Gary''s Student" wrote:

> Function NameExist(s As String) As Boolean
> Dim n As Name
> NameExist = False
> If ActiveWorkbook.Names.Count = 0 Then Exit Function
> For Each n In ActiveWorkbook.Names
> If s = n.Name Then
> NameExist = True
> Exit Function
> End If
> Next
> End Function
>
>
> --
> Gary''s Student - gsnu200826
>
>
> "Rob" wrote:
>
> > Hi. I was wondering if there was a way for a macro to detect if there was a
> > field name already in use for a workbook?
> >
> > I already tried...
> > If Exist Workbooks("Export.xls").Names("DATA1") Then
> >
> > As well as...
> > If Workbooks("Export.xls").Names("DATA1") = True Then
> >
> >
> > Thanks very much,
> > Rob

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Jan 2009
dim myName as Name

Set myName = nothing
on error resume next
set myname = Workbooks("Export.xls").Names("DATA1")
on error goto 0

if myname is nothing then
'doesn't exist
else
'does exist
end if



Rob wrote:
>
> Hi. I was wondering if there was a way for a macro to detect if there was a
> field name already in use for a workbook?
>
> I already tried...
> If Exist Workbooks("Export.xls").Names("DATA1") Then
>
> As well as...
> If Workbooks("Export.xls").Names("DATA1") = True Then
>
> Thanks very much,
> Rob


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can DIR detect if a Folder exists? kirkm Microsoft Excel Programming 2 15th Jun 2009 01:06 PM
how to detect if file exists =?Utf-8?B?SkI=?= Microsoft Access External Data 1 6th Jun 2006 12:42 PM
How to detect if a Sproc exists ? Stan Sainte-Rose Microsoft ADO .NET 4 23rd Nov 2003 04:21 AM
Detect if file exists? DeadManWalking Microsoft Outlook 2 23rd Oct 2003 10:42 AM
How to detect if table exists?? SAG Microsoft Access Database Table Design 8 13th Oct 2003 02:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.