J
John Wirt
I want to write a procedure that will search through a flat text file to
find fields with a certain fieldname (i.e., "KE[ ") , extend the
election to the entire field (i.e., until the next vbCRLF), and then
replace all commas in that selection with semi-colons.
A basic procedure that will do this is shown below, but how can I
replace text within the selected field? Set the current selection to a
selection object and then search and replace in that object?
Public Sub ReplaceSelwSemiColons()
Dim FoundField as Selection
Selection.HomeKey Unit:=wdStory 'go to beginning of document
Do
With Selection.Find
.Text = "KE[ " 'search for next field named KE[^
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
Selection.EndOf Unit:=wdParagraph, Extend:=wdExtend
'if KE[ is found, extend the selection to the entire field
{now, what goes in here to replace all commas with
a semicolon?}
Set FoundField=Selection
{Then what.....?
End If
Selection.Collapse Direction:=wdCollapseEnd
Loop 'loop back to find next instance of the field
End Sub
John Wirt
find fields with a certain fieldname (i.e., "KE[ ") , extend the
election to the entire field (i.e., until the next vbCRLF), and then
replace all commas in that selection with semi-colons.
A basic procedure that will do this is shown below, but how can I
replace text within the selected field? Set the current selection to a
selection object and then search and replace in that object?
Public Sub ReplaceSelwSemiColons()
Dim FoundField as Selection
Selection.HomeKey Unit:=wdStory 'go to beginning of document
Do
With Selection.Find
.Text = "KE[ " 'search for next field named KE[^
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
Selection.EndOf Unit:=wdParagraph, Extend:=wdExtend
'if KE[ is found, extend the selection to the entire field
{now, what goes in here to replace all commas with
a semicolon?}
Set FoundField=Selection
{Then what.....?
End If
Selection.Collapse Direction:=wdCollapseEnd
Loop 'loop back to find next instance of the field
End Sub
John Wirt