C
cgusenetmail
I am trying to write a macro that will look through a document and
verify that the numbers that are found are sequential. All I need to
be able to do is verify that each 2 numbers are sequential. The
document is simple plain text and the numbers all have markers around
them (i.e. [#.###]). I have written something which works for 2
numbers at a time, but I don't know how to make it go throughout the
whole document and mark whenever 2 sets of numbers go out of sequence.
It needs to check every set of 2 numbers and if they are out of
sequence, highlight them or something, so it can be manually checked
easily.
here is my attempt so far (Word2003):
Sub extractnos()
'
'
'
Dim NosFindText As String ' number pattern to search for
Dim NosFoundText1 As String ' first number pattern string found
Dim NosFoundText2 As String ' second number pattern string found
Dim FirstNum As Double ' first number found
Dim SecondNum As Double ' second number found
Dim NumLen1 ' the len for the first number pattern string
Dim NumLen2 ' the len for the second number pattern string
x = 1
NosFindText = "\[*\]"
' search for 2 numbers at a time to compare them
Do While x < 3
With Selection.Find
.Text = NosFindText
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
If x = 1 Then
NosFoundText1 = Selection.Text
End If
x = x + 1
Loop
' extract the numbers from their strings
If Selection.Find.Found = True Then
NosFoundText2 = Selection.Text
NumLen1 = Len(NosFoundText1)
NumLen2 = Len(NosFoundText2)
FirstNum = Mid(NosFoundText1, 2, NumLen1 - 2)
SecondNum = Mid(NosFoundText2, 2, NumLen2 - 2)
If FirstNum > SecondNum Then
StatusBar = "Error!!!" ' if I find an out of sequence
number
End If
End If
End Sub
verify that the numbers that are found are sequential. All I need to
be able to do is verify that each 2 numbers are sequential. The
document is simple plain text and the numbers all have markers around
them (i.e. [#.###]). I have written something which works for 2
numbers at a time, but I don't know how to make it go throughout the
whole document and mark whenever 2 sets of numbers go out of sequence.
It needs to check every set of 2 numbers and if they are out of
sequence, highlight them or something, so it can be manually checked
easily.
here is my attempt so far (Word2003):
Sub extractnos()
'
'
'
Dim NosFindText As String ' number pattern to search for
Dim NosFoundText1 As String ' first number pattern string found
Dim NosFoundText2 As String ' second number pattern string found
Dim FirstNum As Double ' first number found
Dim SecondNum As Double ' second number found
Dim NumLen1 ' the len for the first number pattern string
Dim NumLen2 ' the len for the second number pattern string
x = 1
NosFindText = "\[*\]"
' search for 2 numbers at a time to compare them
Do While x < 3
With Selection.Find
.Text = NosFindText
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
If x = 1 Then
NosFoundText1 = Selection.Text
End If
x = x + 1
Loop
' extract the numbers from their strings
If Selection.Find.Found = True Then
NosFoundText2 = Selection.Text
NumLen1 = Len(NosFoundText1)
NumLen2 = Len(NosFoundText2)
FirstNum = Mid(NosFoundText1, 2, NumLen1 - 2)
SecondNum = Mid(NosFoundText2, 2, NumLen2 - 2)
If FirstNum > SecondNum Then
StatusBar = "Error!!!" ' if I find an out of sequence
number
End If
End If
End Sub