Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-05-2021, 02:09 AM
macropod's Avatar
macropod macropod is offline Would like to shortern the coding for searching docx file names in specific directory Windows 10 Would like to shortern the coding for searching docx file names in specific directory Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
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 example:

Code:
Sub GetDocumentStats()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String
Dim strList As String, i As Long, wdDoc As Document
strDocNm = ActiveDocument.FullName: strFolder = "C:\Sam-Documents\VBA-Word"
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    i = i + 1
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      With .Range.Find
        .Text = strFnd
        .MatchCase = False
        .MatchAllWordForms = False
        .MatchWholeWord = False
        .Execute
        If .Found = True Then strList = strList & vbCr & strFile
      End With
      .Close SaveChanges:=False
    End With
  End If
  ' Let Word do its housekeeping
  DoEvents
  strFile = Dir()
Wend
Set wdDoc = Nothing
MsgBox i & " files processed." & vbCr & "Matches with " & strFnd & " found in:" & strList, vbOKOnly
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Would like to shortern the coding for searching docx file names in specific directory Searching WORD files for specific link ??? ksor Word VBA 1 10-12-2019 08:33 PM
Formula for searching names in one go SilverChat Excel 2 05-07-2018 06:11 PM
Would like to shortern the coding for searching docx file names in specific directory Using Word VBA to change file names in a directory sg11 Word VBA 4 03-22-2018 04:25 AM
Would like to shortern the coding for searching docx file names in specific directory Macro to check the existence of a word docx file and create a new word file with specific content. staicumihai Word VBA 14 11-15-2016 01:42 AM
Would like to shortern the coding for searching docx file names in specific directory How To Apply A VBA Macro to All Subfolders in a Directory of a docx. Extension jc491 Word VBA 8 09-11-2015 08:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:25 AM.


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