Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2017, 05:31 PM
macropod's Avatar
macropod macropod is offline Help creating VBA code to search multiple word documents for specific group of words Windows 7 64bit Help creating VBA code to search multiple word documents for specific group of words Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

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
To do the same for pdfs, you could change:
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]
Reply With Quote
  #2  
Old 07-30-2019, 10:21 AM
srikanthg2310 srikanthg2310 is offline Help creating VBA code to search multiple word documents for specific group of words Windows 8 Help creating VBA code to search multiple word documents for specific group of words Office 2013
Novice
 
Join Date: Jul 2019
Posts: 1
srikanthg2310 is on a distinguished road
Default vba for excel

how do i run the same vba in excel ? also, how do i loop through sub-folders within a folder? thanks.
Reply With Quote
  #3  
Old 07-30-2019, 02:31 PM
macropod's Avatar
macropod macropod is offline Help creating VBA code to search multiple word documents for specific group of words Windows 7 64bit Help creating VBA code to search multiple word documents for specific group of words Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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 srikanthg2310 View Post
how do i run the same vba in excel ?
You don't - the code would have to be completely re-written to be run from Excel.
Quote:
Originally Posted by srikanthg2310 View Post
also, how do i loop through sub-folders within a folder? thanks.
For an idea of the modifications needed to make the above code do that, see: https://www.msofficeforums.com/47347-post12.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help creating VBA code to search multiple word documents for specific group of words 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
Help creating VBA code to search multiple word documents for specific group of words 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
Help creating VBA code to search multiple word documents for specific group of words VBA code to extract specific bookmarks from multiple word files Rattykins Word VBA 4 06-27-2012 10:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:20 PM.


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