How to find and delete orphaned entity names in Solidworks using API?

Hey everyone,

I’m working on a VBA macro to clean up named entities in a SolidWorks part. I use GetNamedEntities() and DeleteEntityName() to go through and remove them.

The issue is:
GetNamedEntities() only returns one name, but I know there are more names showing in the UI (like IMT-4, IMT-5, etc.). Those entities were deleted earlier, so I guess the names are orphaned now.

Is there a way to get a list of all entity names, including ones that don’t belong to any geometry anymore?
Right now I’m only able to delete them if I know the exact names ahead of time and pass them manually to DeleteEntityName("IMT-5").

Is there any workaround or better method to get these orphaned names dynamically?

Thanks in advance!