S
ShaunW
Hi,
I am currently trying to write a VBA macro (Word 2003) that syntax checks
a document. I need to check that a style contains only the following text:
Requirement: aaa_bbb_123, aaa_bbb_123, aaa_bbb_123, aaa_bbb_123,
There is no limit on the number of comma seperated items within the
paragraph, but each item must be in this form.
So I wrote the following code extract which attempts to use ranges to select
a single requirement "aaa_bbb_123," and then reduce the overall (refRng)
range by the currently processed requirement (singleref):
Dim refRng As Range
Dim singleReq As String
Dim singleref As Range
colonIn = InStr(aParagraph, ":")
'Set refrng to be the paragrph minus the text Requiremnet:
and minus the carriage return at the end
Set refRng = mySTS.Range(Start:=aParagraph.Range.Start +
colonIn, _
End:=aParagraph.Range.End - 1)
While (InStr(refRng, ","))
'extract text upto comma
Set singleref = mySTS.Range(Start:=refRng.Start, _
End:=refRng.Start +
InStr(refRng, ","))
singleref.Select
'match string to pattern
If Trim(singleref.Text) Like "?*_?*_?*," Then
Else
mySTS.Comments.Add Range:=singleref,
Text:="SyntaxChecker: Not Matched" & singleref.Text
End If
refRng.SetRange Start:=singleref.End, _
End:=refRng.End
Wend
However, when I attempt to parse the paragraph:
Reference: VE900_ISUP_090, VE900_ISUP_091, VE900_ISUP_092, VE900_ISUP_093,
,VE900_ISUP_094,VE900_ISUP_095, VE900_ISUP096, VE900_ISUP_097
The code gets stuck in an infinate loop due to the text "093,
,VE900_ISUP_094,VE900_ISUP_095, VE900_ISUP096, VE900_ISUP_097"
For each iteration of the loop, the refRng.Start value incriments, but the
value of the refRng.Text remains the same making the value of singleref
always "".
I don't understand why the textual value of the refRng.Text does not shrink
by one character for each iteration of the loop.
Is this just some bad code (which is highly likely) caused by my lack of
understanding of the setrange method, or is there something more untoward
going on?
Any help greatly appreciated as I am fairly new to VBA.
Cheers,
Shaun
I am currently trying to write a VBA macro (Word 2003) that syntax checks
a document. I need to check that a style contains only the following text:
Requirement: aaa_bbb_123, aaa_bbb_123, aaa_bbb_123, aaa_bbb_123,
There is no limit on the number of comma seperated items within the
paragraph, but each item must be in this form.
So I wrote the following code extract which attempts to use ranges to select
a single requirement "aaa_bbb_123," and then reduce the overall (refRng)
range by the currently processed requirement (singleref):
Dim refRng As Range
Dim singleReq As String
Dim singleref As Range
colonIn = InStr(aParagraph, ":")
'Set refrng to be the paragrph minus the text Requiremnet:
and minus the carriage return at the end
Set refRng = mySTS.Range(Start:=aParagraph.Range.Start +
colonIn, _
End:=aParagraph.Range.End - 1)
While (InStr(refRng, ","))
'extract text upto comma
Set singleref = mySTS.Range(Start:=refRng.Start, _
End:=refRng.Start +
InStr(refRng, ","))
singleref.Select
'match string to pattern
If Trim(singleref.Text) Like "?*_?*_?*," Then
Else
mySTS.Comments.Add Range:=singleref,
Text:="SyntaxChecker: Not Matched" & singleref.Text
End If
refRng.SetRange Start:=singleref.End, _
End:=refRng.End
Wend
However, when I attempt to parse the paragraph:
Reference: VE900_ISUP_090, VE900_ISUP_091, VE900_ISUP_092, VE900_ISUP_093,
,VE900_ISUP_094,VE900_ISUP_095, VE900_ISUP096, VE900_ISUP_097
The code gets stuck in an infinate loop due to the text "093,
,VE900_ISUP_094,VE900_ISUP_095, VE900_ISUP096, VE900_ISUP_097"
For each iteration of the loop, the refRng.Start value incriments, but the
value of the refRng.Text remains the same making the value of singleref
always "".
I don't understand why the textual value of the refRng.Text does not shrink
by one character for each iteration of the loop.
Is this just some bad code (which is highly likely) caused by my lack of
understanding of the setrange method, or is there something more untoward
going on?
Any help greatly appreciated as I am fairly new to VBA.
Cheers,
Shaun