Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2022, 02:52 AM
w64bit w64bit is offline Search for docx files having Verdana font used Windows 8 Search for docx files having Verdana font used Office 2013
Novice
Search for docx files having Verdana font used
 
Join Date: Jan 2015
Posts: 16
w64bit is on a distinguished road
Default Search for docx files having Verdana font used

Can anyone please help me with a code to find docx files having Verdana font used?


I can use the code with Graham Mayor's BatchProcessDocuments if it's easier for coding.
Thank you
Reply With Quote
  #2  
Old 04-27-2022, 04:44 PM
Astrid Astrid is offline Search for docx files having Verdana font used Windows 10 Search for docx files having Verdana font used Office 2019
Novice
 
Join Date: Apr 2022
Posts: 5
Astrid is on a distinguished road
Default

If you want to search Verdana in the document's text itself (not headers, footers, textboxes etc), you can use something like this:

Code:
Sub SearchAllFiles()
Dim oDocToFind As Document
Dim oResultDoc As Document
Dim sDocPath As String
Dim sFileName As String
Dim sDocSearchedName As String
Dim oResultRange As Range

  'Close all open documents
  Documents.Close savechanges:=wdPromptToSaveChanges

  'Create new doc for results
  Set oResultDoc = Documents.Add
  
  'Change with the path you want to use
  sDocPath = "E:\Users\Astrid Zeelenberg\Desktop\Testcode\"
  sFileName = Dir(sDocPath & "*.docx")
  
  While sFileName <> ""
    
    'Open document
    Set oDocToFind = Documents.Open(sDocPath & sFileName)
    
    'Search doc for Verdana
    sDocSearchedName = FindFont("Verdana", oDocToFind)
    
    If Trim(sDocSearchedName) <> "" Then
      'Font was found
      'write name to result document
      Set oResultRange = oResultDoc.Content
      oResultRange.Collapse direction:=wdCollapseEnd
      oResultRange.Text = sDocSearchedName & vbCr
    End If
    
    'Close document
    oDocToFind.Close savechanges:=wdDoNotSaveChanges
    
    sFileName = Dir()
    
  Wend
  
End Sub

Function FindFont(sFont As String, oWdDoc As Word.Document) As String
Dim bFound As Boolean
 
  'Find and replace is faster on a selection
  oWdDoc.Content.Select
  
  With Selection.Find
  
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Format = True
    .Font.Name = "Verdana"
    .Wrap = wdFindStop
    
    If .Execute Then
      bFound = True
      FindFont = oWdDoc.Name
    End If
  End With
  
End Function
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for docx files having Verdana font used Run Code on all files and save files as .docx Plokimu77 Word VBA 4 06-05-2016 04:41 PM
VBA Word - Search Within Files Containing A String - Copy Files to New Folder jc491 Word VBA 0 01-09-2016 12:00 PM
Corrupted .docx files Mayberry Word 0 08-29-2015 03:17 AM
Search for docx files having Verdana font used Macros now ok in docx files? techwriterrc12 Word VBA 4 05-09-2013 10:47 AM
Icon for docx files Jazz43 Word 2 10-20-2009 08:34 PM

Other Forums: Access Forums

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