Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #23  
Old 09-19-2012, 04:33 PM
macropod's Avatar
macropod macropod is offline Find, copy and paste into a new page Windows 7 64bit Find, copy and paste into a new page Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, now we have that sorted out, try the following with an input document:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim strFnd As String, wdDoc As Document, i As Long, j As Long, k As Long
Set wdDoc = Documents.Open(File:="Drive:\FilePath\SearchList.doc", Visible:=False, AddToRecentFiles:=False)
strFnd = Replace(wdDoc.Range.Text, vbLf, vbCr)
wdDoc.Close False
Set wdDoc = Nothing
While InStr(strFnd, vbCr & vbCr) > 0
  strFnd = Replace(strFnd, vbCr & vbCr, vbCr)
Wend
strFnd = Left(strFnd, Len(strFnd) - 1)
With ActiveDocument.Range
  j = .End
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^94[!^94]"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found = True
    With .Duplicate
      .Start = .Start + 1
      .MoveEndUntil Cset:="^", Count:=wdForward
      For k = 0 To UBound(Split(strFnd, vbCr))
        If InStr(.Text, Split(strFnd, vbCr)(k)) > 0 Then
          If wdDoc Is Nothing Then Set wdDoc = Documents.Add
          i = i + 1
          While .Characters.First = vbCr
            .Start = .Start + 1
          Wend
          .Copy
          With wdDoc.Range
            .InsertAfter Chr(12)
            If i = 1 Then .InsertAfter "Search Expression: " & strFnd & vbCr
            .InsertAfter "Instance: " & i & vbTab & "First matched on: " & Split(strFnd, vbCr)(k) & vbCr
            .Characters.Last.Paste
            While .Characters.Last.Previous.Previous = vbCr
              .Characters.Last.Previous.Previous.Delete
            Wend
          End With
          Exit For
        End If
      Next
      If .End = j Then Exit Do
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
If Not wdDoc Is Nothing Then wdDoc.Characters.First.Delete
Set wdDoc = Nothing
Application.ScreenUpdating = True
MsgBox i & " instances found."
End Sub
Simply create your input document with a separate line(paragraph) for each entry (no '|' characters for separators), then replace 'Drive:\FilePath\SearchList.doc' in the code with the input document's full path & name.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 09-19-2012 at 10:09 PM. Reason: Code refinement
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find, copy and paste into a new page copy and paste not working Ellie Word 3 11-07-2013 02:23 PM
Can't copy paste irenasobolewska Office 2 10-26-2012 05:09 PM
Find, copy and paste into a new page special copy/paste iconofsin Excel 1 09-15-2010 12:10 AM
Copy - Paste between 2 tables rod147 Excel 1 10-22-2009 08:21 PM
Copy & paste low resolution worriedme Drawing and Graphics 0 06-01-2009 03:05 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft