What is the best way to enumerate the measure formats in a data model? Before I develop some truly awful VBA I want to check with this forum.
Enumeration of the measure info itself is pretty straightforward...
Dim objMs As ModelMeasures
Dim objM As ModelMeasure
Dim objMName As ModelMeasureNames
Dim objMTable As ModelTable
Dim objMFmtBool As ModelFormatBoolean
Dim objMFmtCur As ModelFormatCurrency
Dim objMFmtDate As ModelFormatDate
Dim objMFmtDec As ModelFormatDecimalNumber
Dim objMFmtGen As ModelFormatGeneral
Dim objMFmtPct As ModelFormatPercentageNumber
Dim objMFmtSci As ModelFormatScientificNumber
Dim objMFmtInt As ModelFormatWholeNumber
Dim i%
Set objMs = ActiveWorkbook.Model.ModelMeasures
For Each objM In objMs
Debug.Print objM.name
Debug.Print objM.Formula
Debug.Print objM.Description
Set objMTable = objM.AssociatedTable
Debug.Print objMTable.name
Next objM
If you already know the format you can set the object and get related info, as in
Set objMFmtCur = objM.FormatInformation
Debug.Print objMFmtCur.DecimalPlaces
But of course you'll get an error if you try to set the .FormatInformation to the wrong type of object such as
Set objMFmtBool = objM.FormatInformation
So rather than writing a convoluted error trapping mechanism to test each ModelFormat object, am I missing something simple to tell me the correct format type? Then I can use a Select Case to return the proper format properties.
Enumeration of the measure info itself is pretty straightforward...
Dim objMs As ModelMeasures
Dim objM As ModelMeasure
Dim objMName As ModelMeasureNames
Dim objMTable As ModelTable
Dim objMFmtBool As ModelFormatBoolean
Dim objMFmtCur As ModelFormatCurrency
Dim objMFmtDate As ModelFormatDate
Dim objMFmtDec As ModelFormatDecimalNumber
Dim objMFmtGen As ModelFormatGeneral
Dim objMFmtPct As ModelFormatPercentageNumber
Dim objMFmtSci As ModelFormatScientificNumber
Dim objMFmtInt As ModelFormatWholeNumber
Dim i%
Set objMs = ActiveWorkbook.Model.ModelMeasures
For Each objM In objMs
Debug.Print objM.name
Debug.Print objM.Formula
Debug.Print objM.Description
Set objMTable = objM.AssociatedTable
Debug.Print objMTable.name
Next objM
If you already know the format you can set the object and get related info, as in
Set objMFmtCur = objM.FormatInformation
Debug.Print objMFmtCur.DecimalPlaces
But of course you'll get an error if you try to set the .FormatInformation to the wrong type of object such as
Set objMFmtBool = objM.FormatInformation
So rather than writing a convoluted error trapping mechanism to test each ModelFormat object, am I missing something simple to tell me the correct format type? Then I can use a Select Case to return the proper format properties.