|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Help creating VBA code to search multiple word documents for specific group of words
I have no VBA coding experience and I am looking for help to create a Macro which will search through 200 word documents to determine if any of a group of individual words ( storage, dry, spent, ISFSI or fuel). I also need to have a summary document created which will show the document name and which words were in the document.
Also, Could this macro search for same in a .pdf file or convert the pdf to word and then search? Thanks to anyone who could help. |
#2
|
||||
|
||||
For Word documents, try:
Code:
Sub CollateDocumentData() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, strDocNm As String, strTmp As String, strOut As String Dim wdDoc As Document, i As Long: Const StrFnd As String = "storage,dry,spent,ISFSI,fuel" strDocNm = ActiveDocument.FullName strFolder = GetFolder: If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.doc", vbNormal) While strFile <> "" If strFolder & "\" & strFile <> strDocNm Then Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) strTmp = "" With wdDoc With .Range.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False For i = 0 To UBound(Split(StrFnd, ",")) .Text = Split(StrFnd, ",")(i) .Execute If .Found = True Then strTmp = strTmp & ", " & Split(StrFnd, ",")(i) Next End With If strTmp <> "" Then strOut = strOut & vbCr & strFile & ": " & strTmp .Close SaveChanges:=True End With End If strFile = Dir() Wend Set wdDoc = Nothing ActiveDocument.Range.Text = "The following matches were made:" & strOut 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 strFile = Dir(strFolder & "\*.doc", vbNormal) to: strFile = Dir(strFolder & "\*.pdf", vbNormal) For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
vba for excel
how do i run the same vba in excel ? also, how do i loop through sub-folders within a folder? thanks.
|
#4
|
||||
|
||||
You don't - the code would have to be completely re-written to be run from Excel.
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA code to compile one document based on multiple search terms | Hoxton118 | Word VBA | 4 | 04-04-2021 06:02 AM |
search on multiple word documents | Guy Roth | Word | 7 | 03-06-2017 01:31 PM |
Search for multiple texts in cell, return specific text | mariur89 | Excel | 4 | 12-14-2014 01:33 AM |
Multiple words, one search | return2300 | Word VBA | 0 | 08-30-2013 12:26 PM |
VBA code to extract specific bookmarks from multiple word files | Rattykins | Word VBA | 4 | 06-27-2012 10:02 PM |