View Single Post
 
Old 03-30-2018, 05:44 AM
Cosmo Cosmo is offline Windows Vista Office 2007
Competent Performer
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Testing for 'Object has been deleted' error

I have a function which needs to perform several operations on a table "oTb", one of them will remove empty rows "oTbl.rows(row).delete".

If the table is completely empty, all rows are deleted, and the table is deleted. But the object is still valid, and I need to be able to test to see if the table has been deleted. "oTbl is Nothing" evaluates false, even though the table doesn't exist.

Is there a test that I can do to determine if the object has been deleted, so I can skip any further processing? I'd rather not try accessing a table property and test for an error, I want to do this a proper way (assuming there is a proper way to do so)


Example: this does what I need, but I would prefer not to program by error, I'd rather do a valid test if there is one that I can perform instead

Code:
Private Function tableExists(ByRef oTbl As Word.Table) As Boolean
On Error Resume Next
    tableExists = (oTbl.Rows.count > 0)
End Function


Thanks
Reply With Quote