Tolerance unit export

Hi, I have to pull tolerances from a drawing, right now I have to use two journals, one for millimeters and one for inches.
Is there a way to have a code that will pull whatever the print is in or the dimension?

For mm I use this code:
objExcel.Cells(row, column+2) = myDimension.UpperMetricToleranceValue

For inch I use this code:
objExcel.Cells(row, column+2) = myDimension.UpperToleranceValue

I can't figure out a way to pull the tolerance that is in the dimension using the dimension units.

Thank you,

You can check the dimension's unit preferences to get the dimension units. The simple journal below will report the dimension type, its units, and its upper tolerance value. Note that if no tolerance is shown on the dimension, it will get the default tolerance value. You'll need to add some code to differentiate dims with and without tolerances.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module139
Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each tempDim As Annotations.Dimension In theSession.Parts.Work.Dimensions
lw.WriteLine("dimension type: " & tempDim.GetType.ToString)
lw.WriteLine("dimension units: " & tempDim.GetDimensionPreferences.GetUnitsFormatPreferences.PrimaryDimensionUnit.ToString)
If tempDim.GetDimensionPreferences.GetUnitsFormatPreferences.PrimaryDimensionUnit = Annotations.DimensionUnit.Millimeters Then
lw.WriteLine("metric tolerance upper value: " & tempDim.UpperMetricToleranceValue.ToString)
Else
lw.WriteLine("english tolerance upper value: " & tempDim.UpperToleranceValue.ToString)
End If

Next

lw.Close()

End Sub
End Module