![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Hi to all.
I have over 2000 word files inside a folder and subfolders and i would like to change their font style to "Trebucket MS". I want to change all fonts (just the style not the size etc.) to body, headers and footers. So i was wondering if there is a macro to choose the folder i want and then change the font to "Trebucket MS" in all word documents at once (in that folder and it's subfolders). Thanks ion advanced for your time and help. |
|
#2
|
||||
|
||||
|
The following macro run as a custom process from Document Batch Processes to handle the folders (and subfolders) will change the fonts as required. Do however test it with one document on screen first to establish that it does what you require.
Code:
Function ChangeFont(oDoc As Document) As Boolean
Dim oStory As Range
On Error GoTo err_Handler
For Each oStory In oDoc.StoryRanges
oStory.Font.Name = "Trebucket MS"
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Font.Name = "Trebucket MS"
Wend
End If
Next oStory
Set oStory = Nothing
ChangeFont = True
lbl_Exit:
Exit Function
err_Handler:
ChangeFont = False
Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thanks a lot for your time.
Ok i tried it. It said all documents opened and changed, but the i open the documents and nothing changed. Maybe the "Trebuchet MS" isn't correct for macros, i don't know. Edit: Ok my fault... I said to you in my first post "Trebucket MS" but the right is "Trebuchet MS" I changed it and worked like a charm. Thanks a lot for your help. |
|
#4
|
|||
|
|||
|
Quote:
Hello Sir, Can you please give me the code if I just have to change the font size. Like I have 220 word documents and I just have the change the font size from 14 to 8 in all of them. Just the code & command for font size change. Thank you in advance sir |
|
#5
|
|||
|
|||
|
And if I want to change only Arial to Trebuchet MS what I have to change?
|
|
#6
|
||||
|
||||
|
Code:
Function ChangeFont(oDoc As Document) As Boolean
Dim oStory As Range
On Error GoTo err_Handler
For Each oStory In oDoc.StoryRanges
With oStory.Find
.Font.Name = "Arial"
Do While .Execute
oStory.Font.Name = "Trebuchet MS"
Loop
End With
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
With oStory.Find
.Font.Name = "Arial"
Do While .Execute
oStory.Font.Name = "Trebuchet MS"
Loop
End With
Wend
End If
Next oStory
Set oStory = Nothing
ChangeFont = True
lbl_Exit:
Exit Function
err_Handler:
ChangeFont = False
Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#7
|
|||
|
|||
|
Thank you very much
|
|
#8
|
||||
|
||||
|
In the context of the thread
Code:
Function ChangeFont(oDoc As Document) As Boolean
Dim oStory As Range
On Error GoTo err_Handler
For Each oStory In oDoc.StoryRanges
With oStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Font.Size = 14
.Replacement.Font.Size = 8
.Execute Replace:=wdReplaceAll
End With
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
With oStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Font.Size = 14
.Replacement.Font.Size = 8
.Execute Replace:=wdReplaceAll
End With
Wend
End If
Next oStory
Set oStory = Nothing
ChangeFont = True
lbl_Exit:
Exit Function
err_Handler:
ChangeFont = False
Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#9
|
|||
|
|||
|
Quote:
Where do I enter this code? |
|
#10
|
|||
|
|||
|
Thank you for the prompt reply sir.
|
|
#11
|
||||
|
||||
|
It is a macro intended to work as a custom process with Document Batch Processes (see my original reply in this thread). The code goes in a standard module in the normal template Installing Macros.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#12
|
|||
|
|||
|
Sir I have successfully installed the macro. But when I use the software to bulk process by selecting User Defined Process and type in the macro name. Its not picking up any files to process. I selected the right folder and everything and selected folder option.
Quote:
|
|
| Tags |
| font change, font style |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Batch Comparing Multiple Word Files | scienceguy | Word VBA | 2 | 10-27-2021 07:43 AM |
List all word files in folder and subfolders
|
eduzs | Word VBA | 5 | 06-09-2019 06:20 AM |
| Macro to change/convert/delete txt files in folder+subfolders | NoS | Word VBA | 4 | 03-03-2016 12:10 PM |
Batch add suffix to PDF files in folder
|
Dave T | Windows | 2 | 03-01-2016 08:07 PM |
Change font style and size in multiple documents
|
fitkhan | Word | 1 | 04-27-2011 09:49 PM |