#16
|
||||
|
||||
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] |
#17
|
|||
|
|||
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.
|
#18
|
||||
|
||||
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] |
#19
|
|||
|
|||
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 ."
|
#20
|
||||
|
||||
A Word document would be easier.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#21
|
|||
|
|||
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.
|
#22
|
|||
|
|||
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. |
#23
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 09-19-2012 at 10:09 PM. Reason: Code refinement |
#24
|
|||
|
|||
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?
|
#25
|
|||
|
|||
GOT IT! It's working perfect. Thanks a bunch for all of your help.
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |