Within the code, get the ThreadFeature, then try setting the 'End of Part' to before that feature, before changing the parameter's value that changes the bolt's diameter. Then, while it is still in that state, update the ThreadFeature to the same size thread specification. Then set the 'End of Part' back to after that ThreadFeature (or to end of all features). That should help eliminate the error. However, there is not much I can do to eliminate the possibility of the other portion of the thread specification, after the diameter portion, not matching an existing/available thread specification within the 'thread.xls' file. I generally do not change those types of things by code where I work, so I do not have any super advanced, or highly developed solutions for preventing thread specification mismatches. You would likely have to develop a Sub or Function routine that you supply the specification to, then have it check within that 'thread.xls' file to see if that specification exists for you...and if it does, apply it, but if not, do not apply it. It would likely be a very large and complex code to accomplish that, due to how large that Excel file is, how many sheets, and how many different layouts/formatting there are across all the sheets. Some 'Search' functionality would likely be required.
For further reference, below are some links to online API help about different ways to move the 'End of Part' by code.
This first one lets you move it to just before, or just after a specific feature.
PartFeature.SetEndOfPart (method) (is available to pretty much all sub-types of features, such as ExtrudeFeature & ThreadFeature)
This next one is for moving it to top or bottom of all features in a part.
PartComponentDefinition.SetEndOfPartToTopOrBottom (method)
This next one is just an Object type, for if you attempt to navigate the model browser tree nodes, this is one of the objects you can encounter. Not very useful other than that though.
EndOfFeatures (object)
Wesley Crihfield

(Not an Autodesk Employee)