Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-18-2017, 12:38 AM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time

Hi,

Although my question might be more Windows based than MS Office Word based, I still decided to post this message on your forum because surely other members already had such inquiry.



Lets say in particular main folder, I have multiple subfolders, subsubfolders, subsubsubfolders, etc. In the main folder are located MS Office Word files in different extensions (e.g. doc, docx) in different subfolders/subsubfolders/subsubsubfolders so NOT all Word files are in one second/third hierarchy folder. Those Word files can be few thousands or few tens of thousands, or even just few houndreds.

I am searching for a way how could I find particular word (e.g. ''water'') or particular phrase (e.g. ''old book'') or even entire sentence? So that automated tool I am asking for would show me ALL, without an exception, Word files containing particular keyword(s).

Thank you in advance!
Reply With Quote
  #2  
Old 05-18-2017, 03:28 AM
gmayor's Avatar
gmayor gmayor is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Windows File Explorer advanced search is probably the simplest way to address that.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-18-2017, 04:26 AM
macropod's Avatar
macropod macropod is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 7 64bit Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time 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

Or you could search these forums for some code to recursively loop through folders & sub-folders. I know I've posted some that does just that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 05-18-2017, 05:57 AM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default

gmayor: what you said might work for TXT files but not for Word. I tried and its not working.

macropod: i don't know programming, neither what would I do with ''some code''.
Reply With Quote
  #5  
Old 05-21-2017, 10:51 PM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default

hello......?
Reply With Quote
  #6  
Old 05-21-2017, 11:22 PM
macropod's Avatar
macropod macropod is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 7 64bit Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time 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

Time to learn how to use some VBA code! Try:
Code:
Option Explicit
Public FSO As Object 'a FileSystemObject
Public oFolder As Object 'the folder object
Public oSubFolder As Object 'the subfolders collection
Public oFiles As Object 'the files object
Dim i As Long, strNm As String, strFnd As String, strFile As String, strList As String
 
Sub FindTextInDocs()
' Minimise screen flickering
Application.ScreenUpdating = False
Dim StrFolder As String
' Browse for the starting folder
StrFolder = GetTopFolder
If StrFolder = "" Then Exit Sub
strFnd = InputBox("What is the string to find?", "File Finder")
If Trim(strFnd) = "" Then Exit Sub
strNm = ActiveDocument.FullName
' Search the top-level folder
Call GetFolder(StrFolder & "\")
' Search the subfolders for more files
Call SearchSubFolders(StrFolder)
' Return control of status bar to Word
Application.StatusBar = ""
' Restore screen updating
Application.ScreenUpdating = True
MsgBox i & " files processed." & vbCr & "Matches with " & strFnd & " found in:" & strList, vbOKOnly
End Sub
 
Function GetTopFolder() As String
GetTopFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetTopFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
 
Sub SearchSubFolders(strStartPath As String)
If FSO Is Nothing Then Set FSO = CreateObject("scripting.filesystemobject")
Set oFolder = FSO.GetFolder(strStartPath)
Set oSubFolder = oFolder.subfolders
For Each oFolder In oSubFolder
  Set oFiles = oFolder.Files
  ' Search the current folder
  Call GetFolder(oFolder.Path & "\")
  ' Call ourself to see if there are subfolders below
  SearchSubFolders oFolder.Path
Next
End Sub
 
Sub GetFolder(StrFolder As String)
strFile = Dir(StrFolder & "*.doc", vbNormal)
' Process the files in the folder
While strFile <> ""
  ' Update the status bar is just to let us know where we are
  Application.StatusBar = StrFolder & strFile
  i = i + 1
  Call DocTest(StrFolder & strFile)
  strFile = Dir()
Wend
End Sub
 
Sub DocTest(strDoc As String)
Dim Doc As Document
' Open the document
If strDoc <> strNm Then
  Set Doc = Documents.Open(strDoc, AddToRecentFiles:=False, ReadOnly:=True, Format:=wdOpenFormatAuto, Visible:=False)
  With Doc
    With .Range
      With .Find
        .Text = strFnd
        .MatchCase = False
        .MatchAllWordForms = False
        .MatchWholeWord = False
        .Execute
        If .Found Then strList = strList & vbCr & strFile
      End With
    End With
    .Close SaveChanges:=False
  End With
End If
' Let Word do its housekeeping
DoEvents
Set Doc = Nothing
End Sub
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
Once you've added the code to an empty document (which you might want to save as a macro-enabled document), the sub to run is 'FindTextInDocs'.

As coded, the macro simply displays a message box. You can make it output the results in the active document by changing:
MsgBox i & " files processed." & vbCr & "Matches with " & strFnd & " found in:" & strList, vbOKOnly
in the 'FindTextInDocs' sub to:
ActiveDocument.Range.Text = i & " files processed." & vbCr & "Matches with " & strFnd & " found in:" & strList
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-22-2017, 05:51 AM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default

i somehow managed to integrate that macro's code into the MS Word but after I click on macro to use it and after I click on Run, the folder list occurs when I should choose the folder where I want to search. The problem is that those few thousands or few tens of thousands of MS Word files are NOT available in either of those shown folders, Needed MS Word files are stored on internal network where each employee has his or her own access. Is there any way to to be able to type the folder path instead?
Reply With Quote
  #8  
Old 05-22-2017, 06:34 PM
macropod's Avatar
macropod macropod is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 7 64bit Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time 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

So what's wrong with navigating to the desired folder?

As for inputting the path via an inputbox, sure, but:
a) you hadn't bothered to say that's what you wanted; and:
b) doing so is more error-prone.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 05-22-2017, 10:56 PM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default

In the folders hierarchy there are no wanted folders (located on internal network) where are those thousands of Word files i want to use to search for specific keyword(s) in their content.
Reply With Quote
  #10  
Old 05-23-2017, 12:28 AM
macropod's Avatar
macropod macropod is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 7 64bit Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time 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

You could change:
StrFolder = GetTopFolder
to:
StrFolder = Trim(InputBox("What is the Top Folder?", "Get Top Folder"))
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 05-23-2017, 01:56 AM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default

Compile error, syntax error
Reply With Quote
  #12  
Old 05-25-2017, 06:21 AM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default

still waiting if anyone could please assist with that - the reason is said in my previous message (see above).
Reply With Quote
  #13  
Old 05-25-2017, 06:28 PM
macropod's Avatar
macropod macropod is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 7 64bit Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time 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

The code in post #6, as modified by the edit in post #10 works just fine. Perhaps you made an error when editing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 05-26-2017, 12:05 AM
Abcde Abcde is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 10 Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Office 2013
Novice
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time
 
Join Date: May 2017
Posts: 13
Abcde is on a distinguished road
Default

still compile error
Reply With Quote
  #15  
Old 05-26-2017, 12:14 AM
macropod's Avatar
macropod macropod is offline Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Windows 7 64bit Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time 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

I have re-tested the code and it does not produce an error when modified as directed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Run a macro on multiple docx. files Peter Carter Word VBA 27 12-15-2022 04:10 PM
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Run Code on all files and save files as .docx Plokimu77 Word VBA 4 06-05-2016 04:41 PM
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time seach an Excel list elements in word document 7ajar Word VBA 5 03-16-2011 12:38 PM
Seach ''WORD'' in multiple doc/docx files (different folders!) at the same time Word 2010 not reading docx files Dannyg Word 1 09-22-2010 09:45 PM
Multiple editor at the same time with Word? GaGaGa Word 1 09-19-2010 02:24 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:04 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