tagset base elements

Is it possible to have tags print to an external file grouped in their base element set?

The below code prints the tags to the debug windw, printing the tagsets base element id. The information can then be sorted so it is grouped., but if it is possible, my preference would be for each group to be printed together, making it easier for a DMS solution. (my experience with DMS is minimal so a vba solution is my preference)

Can someone help with the grouping of the information? Thank you