I am trying to write a function to find the most recently created table object in an excel workbook (or I guess worksheet would do).
Running the code below returns the following:
Run-time error '438': Object doesn't support this property or method
I don't understand why but it showing the error to be on line 12. I believe it to be in the "tbl.Created", however this is used on line 11 as well with no issue.
Sub TableWorx()
' Get the name of most recent Table (existing table on new sheet)
Dim ws As Worksheet
Dim tbl As ListObject
Dim newestObjectCreatedTime As Date
Dim eTableName As String
newestObjectCreatedTime = #1/1/1900# 'this is Excel's date with serial no of 0
For Each ws In ThisWorkbook.Worksheets
For Each tbl In ws.ListObjects
If tbl.Created > newestObjectCreatedTime Then
newestObjectCreatedTime = tbl.Created
eTableName = tbl.Name
End If
Next tbl
Next ws
MsgBox "The latest table object: " & eTableName
'eventually will add code to set new table name, it may end up in a separate sub
End Sub
Any suggestions how to get this or an equivalent function working? I am feeling like an ignoramus here.
Attempted running the above code as a function in a module, as a part of an existing function int "ThisWorkbook", as an independent function in "ThisWorkbook".
keep coming back to this error:
Run-time error '438': Object doesn't support this property or method