Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Selection.Find.Execute Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
neo2cents@gmail.com - 07 Mar 2007 13:04 GMT
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
Greg Maxey - 07 Mar 2007 16:56 GMT
You have to repeat .Execute while the item is found:

Sub Locate_in_Doct()
Dim sExcelTextJ
sExcelTextJ = "3.2.1.1.1.2"
ActiveDocument.Range(0, 0).Select
Selection.Find.ClearFormatting
With Selection.Find
 .Text = sExcelTextJ
 While .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
 Wend
End With
End Sub

On Mar 7, 8:04 am, "neo2ce...@gmail.com" <neo2ce...@gmail.com> wrote:
> 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
[quoted text clipped - 32 lines]
> Selection.TypeText Text:=vbCrLf & "Locate Here " & vbCrLf
> End Sub
neo2cents@gmail.com - 07 Mar 2007 17:54 GMT
I tried this but on the call to the sub (new sExcelTextJ value) the
While statement does not execute. I am trying to find out how to reset
the selection properties, but I haven't found it yet. Or is this not
the problem?

> You have to repeat .Execute while the item is found:
>
[quoted text clipped - 55 lines]
>
> - Show quoted text -
neo2cents@gmail.com - 12 Mar 2007 19:16 GMT
The problem I had was not with the selection.find.
When I extracted the string from Excel, I had leading spaces or blanks
that did not
show up in the debugger window.  Adding trim$(  ) to the Excel string
solved my problem.
Thanks,

On Mar 7, 1:54 pm, "neo2ce...@gmail.com" <neo2ce...@gmail.com> wrote:
> I tried this but on the call to the sub (new sExcelTextJ value) the
> While statement does not execute. I am trying to find out how to reset
[quoted text clipped - 62 lines]
>
> - Show quoted text -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.