Hi Leo,
>!Name = xlssheet.Range("Name")
It's usually a bad idea to name things "Name", because so many objects
in both Access and Excel either have a Name property or are themselves
called Name.
That said, you can either check that the name exists before trying to
use it, as shown in the sample procedure:
Sub test()
Dim naN As Excel.Name
Dim strName As String
strNameofRange = "TestName"
For Each naN In ActiveWorkbook.Names
If naN.Name = strNameOfRange Then 'Name Exists
Debug.Print strNameOfRange, naN.RefersToRange.Cells(1).Value
Exit For
End If
Next
End Sub
Or you can use the nonexistent name and trap the resulting error with
somethig like this air code:
Dim varValue as Variant
On Error Resume Next
varValue = xlssheet.Range("TestName").Cells(1).Value
Select Case Err.Number
Case 0 'Success
'Do something with varValue
Case 1004 'expected error if name not found
'do something else
Case Else 'unexpected error
Err.Raise Err.Number, , Err.Description _
& "Range name " & strNameOfRange & " not found."
End Select
On Error Goto 0
>Hi -
>
[quoted text clipped - 31 lines]
>
>Thanks!!
--
John Nurick [Microsoft Access MVP]
Please respond in the newgroup and not by email.