If the code keeps running consistently without issues, then there's really no reason to change it. There are conditions that you can put in to make sure that:
1) The code is run in a part file, although really only necessary if it's an external rule.
2) Make sure there is a solid body in the part file.
3) Make sure there is a flat face available for selection.
4) Make sure that selected face is part of the solid body instead of something else like a work plane.
If ThisApplication.ActiveDocument.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
MsgBox("Part File must be Active.")
Exit Sub
End If
If ThisApplication.ActiveDocument.ComponentDefinition.SurfaceBodies.Count = 0 Then
MsgBox("Part File must contain a body.")
Exit Sub
End If
blnPlanarFaceCheck = False
For Each objSurfaceBody As SurfaceBody In ThisApplication.ActiveDocument.ComponentDefinition.SurfaceBodies
For Each objFace As Face In objSurfaceBody.Faces
If objFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
blnPlanarFaceCheck = True
GoTo jmpFaceCheck
End If
Next
Next
jmpFaceCheck : If blnPlanarFaceCheck = False Then
MsgBox("There must be a flat face for selection.")
Exit Sub
End If
jmpFaceSelection : objFaceSelection = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Planer Face to Calculate Area, Ix, and Iy Properties.")
If objFaceSelection.ObjectType <> Inventor.ObjectTypeEnum.kFaceObject Then
MsgBox("A surface face must be selected.")
GoTo jmpFaceSelection
End If
I left the full code threads in so you can make your own shorthands or use ones you've already made. ThisApplication.ActiveDocument is meant more for running in an external rule, if your code is going to be a rule attached to your part file template then ThisDoc.Document will work just fine and there'll be no need for the first part of the code to make sure it's running from a part document.
One other thing I noticed is your method of undoing the face sketch for calculation, it assumes it takes 4 undo methods every time to get back to where you were at the beginning of the code. I suggest you implement code that controls the Transaction Manager so that the number of undo methods is irrelevant.
oTransaction = ThisApplication.TransactionManager.StartTransaction(doc, "Inertia Calculation")
oSK = oCD.Sketches.Add(oFace)
oSK.Edit
oCommandMgr.ControlDefinitions("SketchProjectCutEdgesCmd").Execute
oProfile = oSK.Profiles.AddForSolid
dArea = oProfile.RegionProperties.Area
Dim adPrincipalMoments(2) As Double
oProfile.RegionProperties.PrincipalMomentsofInertia(adPrincipalMoments(0), adPrincipalMoments(1), adPrincipalMoments(2))
oTransaction.Abort
This will undo your sketch operations but the adPrincipalMoments will still be in code memory to calculate and copy to your iProperties.
The last thing I recommend is to turn off screen updating, as it currently is, your computer is spending time updating the screen to show exactly what's happening during the sketch operations. Before you do the sketch operations, just put in the line ThisApplication.ScreenUpdating = False, then turn that back to True at the end of your code. This isn't necessary but it may speed your code up a bit.