JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,691
- Office Version
- 365
- Platform
- Windows
A macro I am working on needs to access one or more auxilliary tables. The table names are formed by prefixing "tbl" to a data field. So if the data field contains "Body Type", the table name will be "tblBodyType".
I want to add code to check that (a) the table name exists and (b) it is a table.
I checked several "solutions", but they all seemed overly complicated. Probably the simplest is this function.
It probably works, but I didn't test it.
But isn't there a simpler way, something like this?
There are dozens of properties accessible after the ".". Surely a way to test if it exists is one of them.
And then if it exists, I need to check that it is a table.
Thanks
I want to add code to check that (a) the table name exists and (b) it is a table.
I checked several "solutions", but they all seemed overly complicated. Probably the simplest is this function.
VBA Code:
Function NameExists(rName As String) As Boolean
Dim errTest As String
On Error Resume Next
errTest = ThisWorkbook.Names(rName).Value
NameExist = CBool(Err.Number = 0)
On Error GoTo 0
End Function
It probably works, but I didn't test it.
But isn't there a simpler way, something like this?
Code:
If range(rName).exists ...
There are dozens of properties accessible after the ".". Surely a way to test if it exists is one of them.
And then if it exists, I need to check that it is a table.
Thanks