M
msnews.microsoft.com
I'd like to write a macro that would search through a word document and
search for an instance of text enclosed with square brackets "[.....]" and
parse out each option that immediately follows.
Example text from document would be as follows:
If changes are required, notify [Departmental Representative] [Engineer]
[Consultant] of these changes before they are made.
I'd like to essentially parse out the following options where I'd place them
on a form for the user to select the correct option:
Departmental Representative
Engineer
Consultant
So if the user selected Engineer then I'd like to update the original
document to read:
If changes are required, notify Engineer of these changes before they are
made.
At this point I'd run the macro again looking for the next set of brackets.
I know how to search for the start point with the following code:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\[*\]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
This code will find [Departmental Representative] but from there I'm not
sure how to parse immediately after the close bracket to see if there is
another option (space followed by a open bracket.
Does anyone know how I would go about doing this?
Thanks
Dustin Wilson
search for an instance of text enclosed with square brackets "[.....]" and
parse out each option that immediately follows.
Example text from document would be as follows:
If changes are required, notify [Departmental Representative] [Engineer]
[Consultant] of these changes before they are made.
I'd like to essentially parse out the following options where I'd place them
on a form for the user to select the correct option:
Departmental Representative
Engineer
Consultant
So if the user selected Engineer then I'd like to update the original
document to read:
If changes are required, notify Engineer of these changes before they are
made.
At this point I'd run the macro again looking for the next set of brackets.
I know how to search for the start point with the following code:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\[*\]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
This code will find [Departmental Representative] but from there I'm not
sure how to parse immediately after the close bracket to see if there is
another option (space followed by a open bracket.
Does anyone know how I would go about doing this?
Thanks
Dustin Wilson