Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-26-2019, 12:13 AM
kalagas kalagas is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2019
Novice
Batch change the font style in multiple word files inside folder and subfolders
 
Join Date: Nov 2019
Posts: 9
kalagas is on a distinguished road
Default Batch change the font style in multiple word files inside folder and subfolders

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.
Reply With Quote
  #2  
Old 11-26-2019, 01:37 AM
gmayor's Avatar
gmayor gmayor is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 11-26-2019, 02:28 AM
kalagas kalagas is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2019
Novice
Batch change the font style in multiple word files inside folder and subfolders
 
Join Date: Nov 2019
Posts: 9
kalagas is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-21-2023, 08:48 AM
w64bit w64bit is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2021
Novice
 
Join Date: Jan 2015
Posts: 16
w64bit is on a distinguished road
Default

And if I want to change only Arial to Trebuchet MS what I have to change?
Reply With Quote
  #5  
Old 07-21-2023, 09:24 AM
gmayor's Avatar
gmayor gmayor is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #6  
Old 07-21-2023, 02:14 PM
w64bit w64bit is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2021
Novice
 
Join Date: Jan 2015
Posts: 16
w64bit is on a distinguished road
Default

Thank you very much
Reply With Quote
  #7  
Old 09-12-2023, 01:15 AM
profitbookie profitbookie is offline Batch change the font style in multiple word files inside folder and subfolders Windows 11 Batch change the font style in multiple word files inside folder and subfolders Office 2016
Novice
 
Join Date: Sep 2023
Posts: 4
profitbookie is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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


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
Reply With Quote
  #8  
Old 09-12-2023, 01:27 AM
gmayor's Avatar
gmayor gmayor is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #9  
Old 09-12-2023, 01:29 AM
profitbookie profitbookie is offline Batch change the font style in multiple word files inside folder and subfolders Windows 11 Batch change the font style in multiple word files inside folder and subfolders Office 2016
Novice
 
Join Date: Sep 2023
Posts: 4
profitbookie is on a distinguished road
Default

Thank you for the prompt reply sir.
Reply With Quote
  #10  
Old 09-14-2023, 12:58 AM
profitbookie profitbookie is offline Batch change the font style in multiple word files inside folder and subfolders Windows 11 Batch change the font style in multiple word files inside folder and subfolders Office 2016
Novice
 
Join Date: Sep 2023
Posts: 4
profitbookie is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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

Where do I enter this code?
Reply With Quote
  #11  
Old 09-14-2023, 10:44 PM
gmayor's Avatar
gmayor gmayor is offline Batch change the font style in multiple word files inside folder and subfolders Windows 10 Batch change the font style in multiple word files inside folder and subfolders Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #12  
Old 10-05-2023, 05:13 AM
profitbookie profitbookie is offline Batch change the font style in multiple word files inside folder and subfolders Windows 11 Batch change the font style in multiple word files inside folder and subfolders Office 2016
Novice
 
Join Date: Sep 2023
Posts: 4
profitbookie is on a distinguished road
Default

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:
Originally Posted by gmayor View Post
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.
Reply With Quote
Reply

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
Batch change the font style in multiple word files inside folder and subfolders 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 change the font style in multiple word files inside folder and subfolders Batch add suffix to PDF files in folder Dave T Windows 2 03-01-2016 08:07 PM
Batch change the font style in multiple word files inside folder and subfolders Change font style and size in multiple documents fitkhan Word 1 04-27-2011 09:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:28 PM.


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