P
Poli
Please Help me I am writing a Macro using Word 2007 and Windows XP so that it
looks at differnt FormFields and gives me a Mininum and Maximum value into
another field. It give me error though. Here it is:
Sub GetMinMaxValueA()
Dim EntryFlag As Boolean
EntryFlag = False
varMAX_A = 0
varMIN_A = 9999.99
If Application.ActiveDocument.Fields("FHZ_A").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_A").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_A").Data
End If
If Application.ActiveDocument.Fields("FHZ_A").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_A").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_E").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_E").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_E").Data
End If
If Application.ActiveDocument.Fields("FHZ_E").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_E").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_I").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_I").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_I").Data
End If
If Application.ActiveDocument.Fields("FHZ_I").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_I").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_M").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_M").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_M").Data
End If
If Application.ActiveDocument.Fields("FHZ_M").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_M").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_Q").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_Q").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_Q").Data
End If
If Application.ActiveDocument.Fields("FHZ_Q").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_Q").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_U").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_U").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_U").Data
End If
If Application.ActiveDocument.Fields("FHZ_U").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_U").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_Y").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_Y").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_Y").Data
End If
If Application.ActiveDocument.Fields("FHZ_Y").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_Y").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AC").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AC").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AC").Data
End If
If Application.ActiveDocument.Fields("FHZ_AC").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AC").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AG").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AG").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AG").Data
End If
If Application.ActiveDocument.Fields("FHZ_AG").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AG").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AK").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AK").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AK").Data
End If
If Application.ActiveDocument.Fields("FHZ_AK").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AK").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AO").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AO").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AO").Data
End If
If Application.ActiveDocument.Fields("FHZ_AO").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AO").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AS").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AS").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AS").Data
End If
If Application.ActiveDocument.Fields("FHZ_AS").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AS").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AW").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AW").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AW").Data
End If
If Application.ActiveDocument.Fields("FHZ_AW").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AW").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BA").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BA").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BA").Data
End If
If Application.ActiveDocument.Fields("FHZ_BA").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BA").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BE").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BE").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BE").Data
End If
If Application.ActiveDocument.Fields("FHZ_BE").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BE").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BI").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BI").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BI").Data
End If
If Application.ActiveDocument.Fields("FHZ_BI").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BI").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BM").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BM").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BM").Data
End If
If Application.ActiveDocument.Fields("FHZ_BM").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BM").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BQ").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BQ").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BQ").Data
End If
If Application.ActiveDocument.Fields("FHZ_BQ").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BQ").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BU").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BU").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BU").Data
End If
If Application.ActiveDocument.Fields("FHZ_BU").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BU").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BY").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BY").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BY").Data
End If
If Application.ActiveDocument.Fields("FHZ_BY").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BY").Data
End If
EntryFlag = True
End If
If EntryFlag = False Then
Application.ActiveDocument.Fields("TOTMAX_A").Data = ""
Else
Application.ActiveDocument.Fields("TOTMAX_A").Data = varMAX_A
End If
If EntryFlag = False Then
Application.ActiveDocument.Fields("TOTMIN_A").Data = ""
Else
Application.ActiveDocument.Fields("TOTMIN_A").Data = varMIN_A
End If
EntryFlag = False
End Sub
looks at differnt FormFields and gives me a Mininum and Maximum value into
another field. It give me error though. Here it is:
Sub GetMinMaxValueA()
Dim EntryFlag As Boolean
EntryFlag = False
varMAX_A = 0
varMIN_A = 9999.99
If Application.ActiveDocument.Fields("FHZ_A").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_A").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_A").Data
End If
If Application.ActiveDocument.Fields("FHZ_A").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_A").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_E").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_E").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_E").Data
End If
If Application.ActiveDocument.Fields("FHZ_E").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_E").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_I").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_I").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_I").Data
End If
If Application.ActiveDocument.Fields("FHZ_I").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_I").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_M").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_M").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_M").Data
End If
If Application.ActiveDocument.Fields("FHZ_M").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_M").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_Q").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_Q").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_Q").Data
End If
If Application.ActiveDocument.Fields("FHZ_Q").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_Q").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_U").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_U").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_U").Data
End If
If Application.ActiveDocument.Fields("FHZ_U").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_U").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_Y").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_Y").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_Y").Data
End If
If Application.ActiveDocument.Fields("FHZ_Y").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_Y").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AC").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AC").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AC").Data
End If
If Application.ActiveDocument.Fields("FHZ_AC").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AC").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AG").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AG").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AG").Data
End If
If Application.ActiveDocument.Fields("FHZ_AG").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AG").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AK").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AK").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AK").Data
End If
If Application.ActiveDocument.Fields("FHZ_AK").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AK").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AO").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AO").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AO").Data
End If
If Application.ActiveDocument.Fields("FHZ_AO").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AO").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AS").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AS").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AS").Data
End If
If Application.ActiveDocument.Fields("FHZ_AS").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AS").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_AW").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_AW").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_AW").Data
End If
If Application.ActiveDocument.Fields("FHZ_AW").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_AW").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BA").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BA").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BA").Data
End If
If Application.ActiveDocument.Fields("FHZ_BA").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BA").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BE").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BE").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BE").Data
End If
If Application.ActiveDocument.Fields("FHZ_BE").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BE").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BI").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BI").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BI").Data
End If
If Application.ActiveDocument.Fields("FHZ_BI").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BI").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BM").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BM").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BM").Data
End If
If Application.ActiveDocument.Fields("FHZ_BM").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BM").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BQ").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BQ").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BQ").Data
End If
If Application.ActiveDocument.Fields("FHZ_BQ").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BQ").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BU").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BU").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BU").Data
End If
If Application.ActiveDocument.Fields("FHZ_BU").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BU").Data
End If
EntryFlag = True
End If
If Application.ActiveDocument.Fields("FHZ_BY").Data <> 0 Then
If Application.ActiveDocument.Fields("FHZ_BY").Data > varMAX_A Then
varMAX_A = Application.ActiveDocument.Fields("FHZ_BY").Data
End If
If Application.ActiveDocument.Fields("FHZ_BY").Data < varMIN_A Then
varMIN_A = Application.ActiveDocument.Fields("FHZ_BY").Data
End If
EntryFlag = True
End If
If EntryFlag = False Then
Application.ActiveDocument.Fields("TOTMAX_A").Data = ""
Else
Application.ActiveDocument.Fields("TOTMAX_A").Data = varMAX_A
End If
If EntryFlag = False Then
Application.ActiveDocument.Fields("TOTMIN_A").Data = ""
Else
Application.ActiveDocument.Fields("TOTMIN_A").Data = varMIN_A
End If
EntryFlag = False
End Sub