The problem has to do with which methods are available for "DerivedParameter" objects (which are part of the
Document.ComponentDefinition.Parameters.DerivedParameterTables(i).DerivedParameters
collection) as opposed to "DerivedPartEntity" objects (which are part of the
Document.ComponentDefinition.ReferenceComponents.DerivedPartComponents(i).Definition.Parameters
collection) -- both of which are different ways of accessing derived parameters.
The "InUse" method is only available for "DerivedParameter" and regular old "Parameter" objects, while the "IncludeEntity" method is only available for "DerivedPartEntity" objects.
You need to iterate through all "DerivedPartEntitity" parameter objects, check if a parameter of the same name is "InUse", and if it's not then use the "IncludeEntity" method on the "DerivedPartEntity" to remove it.
Another thing I've found is that for some reason you have to set the derived part component definition back to itself in order for the "IncludeEntity" method to take effect.
The following code should work for you (bear in mind there is no error handling):
Dim oDoc As PartDocument = ThisDoc.Document
For Each oDerivedPartComponent As Inventor.DerivedPartComponent In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
Dim oDerivedPartDefinition As Inventor.DerivedPartDefinition = oDerivedPartComponent.Definition
For Each oParameterEntity As Inventor.DerivedPartEntity In oDerivedPartDefinition.Parameters
If Not Parameter.Param(oParameterEntity.ReferencedEntity.Name).InUse Then
oParameterEntity.IncludeEntity = False
End If
Next 'Derived parameter
oDerivedPartComponent.Definition = oDerivedPartDefinition
Next 'Derived part component
@Anonymous's code essentially does the same thing but with much more extensive proper checks, error handling, and user-friendly messages. However, one interesting thing I noticed about his code is it does not in any way check if a derived parameter is used before trying to delete it. The code simply tries to delete every derived parameter, and somehow Inventor is smart enough to not error out, and keep the parameter anyway, if it's used, which is pretty neat.
So the if-statement to check if the parameter is "InUse" really isn't necessary, and the code above could simply be:
Dim oDoc As PartDocument = ThisDoc.Document
For Each oDerivedPartComponent As Inventor.DerivedPartComponent In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
Dim oDerivedPartDefinition As Inventor.DerivedPartDefinition = oDerivedPartComponent.Definition
For Each oParameterEntity As Inventor.DerivedPartEntity In oDerivedPartDefinition.Parameters
oParameterEntity.IncludeEntity = False
Next 'Derived parameter
oDerivedPartComponent.Definition = oDerivedPartDefinition
Next 'Derived part component