#1
|
|||
|
|||
search on multiple word documents
Is there any tool of office or addon to it that allow me to search for a text that can be in one of several word documents that are related to each other and located in the same folder?
I actullay split one big document to several ones (it's easy to maintain them this way) but I'd like to be able to search and find in all of them at once. |
#2
|
||||
|
||||
Hi Guy,
You could do that with a macro like: Code:
Sub MultiDocumentSearch() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, wdDoc as Document, strFind as String strFolder = GetFolder If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.doc", vbNormal) strFind = InputBox("String to Find?") If strFind = "" Then Exit Sub While strFile <> "" Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc.Range.Find .ClearFormatting .Text = strFind .Replacement.Text = "^&" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = True .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With wdDoc.Close SaveChanges:=True strFile = Dir() Wend Set wdDoc = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks - but I am not experienced with Macros and don't want to start maintaining one.
So I am still looking for some tool that already have a proven implementation of such functionality |
#4
|
||||
|
||||
Hi Guy,
There may be some commercial applications, but they'll be less customizable to your needs than a macro such as the one I posted. Furthermore, a commercial application will quite possibly be nothing more than a macro distributed as an add-in. In any event, the macro I posted should require no maintenance on your part - all that needs to be maintained in the file containing the Find/Replace list (something almost anyone could do).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
What does this macro actually do? I installed the macro in a .docm file and ran the code. I selected a folder and search string. There were no messages but I don't know where to get the results.
|
#6
|
||||
|
||||
It does what the OP asked for - find & replace a nominated string in all documents in a folder. The results will be in the updated files.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
I asked because I could not see results, and thought I’m not understanding how it works.
Your macro code includes: .Replacement.Text = "^&" question1: Is “^&” a code? When I changed this to .Replacement.Text = “XX” I could see my target files were changed. But I couldn’t see changes with “^&”. question2. What is the “Find/Replace” list that you mentioned? question3: I understood the OP was asking for “find”, not “find/replace”. That’s what I was looking for also. There are several ways to report finds to the user. One is to stop at the first occurrence and display the document (the page, with the found word highlighted). This is helpful when the user wants to read the page, but does not want to replace anything. Has that option been discussed here? Thanks for your help. |
#8
|
||||
|
||||
1. The ^& is a standard Find/Replace replacement expression. The fact it's used in a macro makes no difference. All it does is replace what's found with itself. As I said in my reply to the OP:
Quote:
2. The 'Find/Replace list' referred to in post #4 could be an array or pair of arrays built into the code itself, a series of tab-delimited paragraphs in a document or plain text file, a two-column Word table, two columns in an Excel workbook, etc., etc. Different code is required for each kind of list. For code that uses an Excel workbook for the list, see: https://www.msofficeforums.com/word-...html#post34254 3. Quite clearly, the option to do anything of substance has not been discussed in this thread. The code provided is little more than a skeleton. If you want something that provides a measure of interactivity, see: https://www.msofficeforums.com/word-...html#post31849 If your needs are different, I suggest you start a new thread setting out exactly what you're trying to achieve.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
search, search folders |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replace text in multiple documents? | Roscoe | Word VBA | 7 | 07-31-2017 04:02 PM |
Word 2010 / Master Index / Multiple Documents | bawrites | Word | 0 | 08-09-2011 11:02 AM |
Change Multiple Documents from US to UK language | swifty2010 | Word | 1 | 03-08-2011 02:00 PM |
2007 merging multiple documents into one master | hugheso | Word | 0 | 04-02-2009 04:31 AM |
page numbering across multiple documents | reitdesign | Word | 3 | 12-12-2008 11:55 AM |