Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 09-18-2012, 03:12 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: 21,956
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


Yes, you can read from a list, but that's not going to change anything. Do note that, as coded, the searches are case sensitive. Perhaps that's the issue.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #17  
Old 09-18-2012, 04:39 PM
jperez84 jperez84 is offline Find, copy and paste into a new page Windows XP Find, copy and paste into a new page Office 2007
Novice
Find, copy and paste into a new page
 
Join Date: Sep 2012
Posts: 21
jperez84 is on a distinguished road
Default

I will check into the case sensitivity. The reason I'm asking about the list is because 256 characters isn't enough so I would have to do multiple runs and then it would save to multiple files instead of one.
Reply With Quote
  #18  
Old 09-18-2012, 04:58 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: 21,956
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

Let's get the basic issues sorted out first, then we can work on the list.

BTW, what would the list be - a Word document, text file, something else? Would you intend to have both the primary and secondary strings in it?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #19  
Old 09-18-2012, 05:04 PM
jperez84 jperez84 is offline Find, copy and paste into a new page Windows XP Find, copy and paste into a new page Office 2007
Novice
Find, copy and paste into a new page
 
Join Date: Sep 2012
Posts: 21
jperez84 is on a distinguished road
Default

It could be a Word doc or Excel, whichever is easier. For this macro it's only one search criteria. Another question on this macro is how many lines it will copy. For the other macro only the first search criteria changes. For the second search criteria it's always the same search strings, "NAM", "DOB" or in this files case ".QW ."
Reply With Quote
  #20  
Old 09-18-2012, 05:20 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: 21,956
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

Quote:
Originally Posted by jperez84 View Post
It could be a Word doc or Excel, whichever is easier.
A Word document would be easier.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #21  
Old 09-19-2012, 10:17 AM
jperez84 jperez84 is offline Find, copy and paste into a new page Windows XP Find, copy and paste into a new page Office 2007
Novice
Find, copy and paste into a new page
 
Join Date: Sep 2012
Posts: 21
jperez84 is on a distinguished road
Default

I'll put in 5 different array separated by '|' and it will only find 1 sometimes 2. However, if I search all 5 by running the macro 5 times and only putting in 1 array at a time it will find all 5.
Reply With Quote
  #22  
Old 09-19-2012, 11:57 AM
jperez84 jperez84 is offline Find, copy and paste into a new page Windows XP Find, copy and paste into a new page Office 2007
Novice
Find, copy and paste into a new page
 
Join Date: Sep 2012
Posts: 21
jperez84 is on a distinguished road
Default

OK, I figured it out. I have all of my arrays in a doc and I would copy and paste a chunk into the input box. I guess it was also copying something in the back ground that was interfering. If I put them in one pay one with the '|' separating them it works. If we could have it read directly from a Word file it would be much easier and I would really appreciate your help.

Thanks a million.
Reply With Quote
  #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: 21,956
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
  #24  
Old 09-20-2012, 07:52 AM
jperez84 jperez84 is offline Find, copy and paste into a new page Windows XP Find, copy and paste into a new page Office 2007
Novice
Find, copy and paste into a new page
 
Join Date: Sep 2012
Posts: 21
jperez84 is on a distinguished road
Default

Thanks. It's working. It didn't find all of the search arrays even though I know they're in the doc. Is there a way for the macro to print out a list at the end of the doc showing which ones weren't found?
Reply With Quote
  #25  
Old 09-20-2012, 11:34 AM
jperez84 jperez84 is offline Find, copy and paste into a new page Windows XP Find, copy and paste into a new page Office 2007
Novice
Find, copy and paste into a new page
 
Join Date: Sep 2012
Posts: 21
jperez84 is on a distinguished road
Default

GOT IT! It's working perfect. Thanks a bunch for all of your help.
Reply With Quote
Reply

Thread Tools
Display Modes


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 10:43 AM.


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