![]() |
|
|
|
#1
|
||||
|
||||
|
For example:
Code:
Option Explicit
Dim FSO As Object, oFolder As Object, StrFolds As String
Sub Main()
Dim TopLevelFolder As String, TheFolders As Variant, aFolder As Variant, i As Long
TopLevelFolder = GetFolder
If TopLevelFolder = "" Then Exit Sub
StrFolds = vbCr & TopLevelFolder
If FSO Is Nothing Then
Set FSO = CreateObject("Scripting.FileSystemObject")
End If
'Get the sub-folder structure
Set TheFolders = FSO.GetFolder(TopLevelFolder).SubFolders
For Each aFolder In TheFolders
RecurseWriteFolderName (aFolder)
Next
'Process the documents in each folder
For i = 1 To UBound(Split(StrFolds, vbCr))
Call UpdateDocuments(CStr(Split(StrFolds, vbCr)(i)))
Next
End Sub
Sub RecurseWriteFolderName(aFolder)
Dim SubFolders As Variant, SubFolder As Variant
Set SubFolders = FSO.GetFolder(aFolder).SubFolders
StrFolds = StrFolds & vbCr & CStr(aFolder)
On Error Resume Next
For Each SubFolder In SubFolders
RecurseWriteFolderName (SubFolder)
Next
End Sub
Sub UpdateDocuments(oFolder As String)
Application.ScreenUpdating = False
Dim strInFolder As String, strFile As String, wdDoc As Document, wdStry As Range, wdStl As Style
strInFolder = oFolder
strFile = Dir(strInFolder & "\*.doc", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strInFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
For Each wdStl In .Styles
With wdStl.Font
If .Name = "Arial" Then .Name = "Calibri"
End With
Next
For Each wdStry In .StoryRanges
With wdStry.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Text = ""
.Replacement.Text = ""
.Font.Name = "Arial"
.Replacement.Font.Name = "Calibri"
.Execute Replace:=wdReplaceAll
End With
Next
'Save and close the document
.Close SaveChanges:=True
End With
strFile = Dir()
Wend
Set wdDoc = Nothing
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Replace or apply new header in multiple files
|
Carchee | Word VBA | 42 | 07-10-2024 08:47 AM |
Replace lines of text from header in multiple files
|
PolarPop | Word VBA | 6 | 05-27-2022 01:43 PM |
| Replace all Images with ordinal numbers in multiple files | beginner | Word | 0 | 09-19-2021 02:19 AM |
| Find and replace header text across multiple files | LG1972 | Excel | 1 | 12-25-2018 04:27 AM |
Macro to Find & Replace Font formats for Multiple Values
|
GemBox | Word | 6 | 03-12-2018 05:24 AM |