N
neo2cents
I am pulling a number (eg, 3.2.1.1.1.2) from an Excel doct and then
trying to locate that position in a Word(2003) doct., and insert some
text below that line. The sub works properly the first time through,
but fails after that. The cursor ends up at the top of the doct but
the Find.execute does not happen after that. Can someone help me with
this?
Thanks
Sub Locate_in_Doct()
'
' Locate_in_Doct Macro
'
'
ActiveDocument.Range(0, 0).Select
Selection.Find.ClearFormatting
With Selection.Find
.Text = sExcelTextJ ' Example "3.2.1.1.1.2" (SExcelTextJ
is a Public String)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Collapse Direction:=wdCollapseEnd
If Selection.IPAtEndOfLine = False Then
Selection.EndKey Unit:=wdLine, Extend:=wdMove
End If
Selection.TypeText Text:=vbCrLf & "Locate Here " & vbCrLf
End Sub
trying to locate that position in a Word(2003) doct., and insert some
text below that line. The sub works properly the first time through,
but fails after that. The cursor ends up at the top of the doct but
the Find.execute does not happen after that. Can someone help me with
this?
Thanks
Sub Locate_in_Doct()
'
' Locate_in_Doct Macro
'
'
ActiveDocument.Range(0, 0).Select
Selection.Find.ClearFormatting
With Selection.Find
.Text = sExcelTextJ ' Example "3.2.1.1.1.2" (SExcelTextJ
is a Public String)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Collapse Direction:=wdCollapseEnd
If Selection.IPAtEndOfLine = False Then
Selection.EndKey Unit:=wdLine, Extend:=wdMove
End If
Selection.TypeText Text:=vbCrLf & "Locate Here " & vbCrLf
End Sub