#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |