Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2024, 04:14 AM
w64bit w64bit is offline Replace font in Normal Style Windows 10 Replace font in Normal Style Office 2021
Novice
Replace font in Normal Style
 
Join Date: Jan 2015
Posts: 19
w64bit is on a distinguished road
Default Replace font in Normal Style

I tried to change this code to replace the Normal Style font when it's Arial to Calibri, but I cannot make it work.
I am using it with Batch Process Documents 4.9 (Graham Mayor).
Can you please give me a little help?
Thank you
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 = "Arial"
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                oStory.Font.Name = "Calibri"
            Wend
        End If
    Next oStory
    Set oStory = Nothing
    ChangeFont = True
lbl_Exit:
    Exit Function
err_Handler:
    ChangeFont = False
    Resume lbl_Exit
End Function

Reply With Quote
  #2  
Old 09-18-2024, 05:00 AM
vivka vivka is offline Replace font in Normal Style Windows 7 64bit Replace font in Normal Style Office 2016
Expert
 
Join Date: Jul 2023
Posts: 293
vivka is on a distinguished road
Default

Hi! What about this one:
Code:
Function ChangeFont(oDoc As Document) As Boolean

Dim oStory As range
    On Error GoTo err_Handler
    For Each oStory In oDoc.StoryRanges
        If oStory.Font.Name = "Arial" Then
                oStory.Font.Name = "Calibri"
        End If
    Next oStory
    Set oStory = Nothing
lbl_Exit:
    Exit Sub
err_Handler:
    ChangeFont = False
    Resume lbl_Exit
End Function
Reply With Quote
  #3  
Old 09-18-2024, 05:46 AM
w64bit w64bit is offline Replace font in Normal Style Windows 10 Replace font in Normal Style Office 2021
Novice
Replace font in Normal Style
 
Join Date: Jan 2015
Posts: 19
w64bit is on a distinguished road
Default

Compile error:
Exit Sub not allowed in Function or Property

I changed to Exit function.
The code it's working with this change but ...
the code changed the text font and not the Normal Style font.
Reply With Quote
  #4  
Old 09-18-2024, 10:11 AM
Italophile Italophile is offline Replace font in Normal Style Windows 11 Replace font in Normal Style Office 2021
Expert
 
Join Date: Mar 2022
Posts: 542
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Changing the font of the Normal style is as simple as:

Code:
Function ChangeFont(oDoc As Document) As Boolean
    Dim oStory As Range
    On Error GoTo err_Handler
    oDoc.Styles(wdStyleNormal).Font.Name = "Calibri"
    ChangeFont = True
lbl_Exit:
    Exit Function
err_Handler:
    ChangeFont = False
    Resume lbl_Exit
End Function
However, changing the Normal style in this way means it will no longer be the same as the document defaults which may lead to Table Styles not working correctly. It is not possible to set the document defaults using VBA.
Reply With Quote
  #5  
Old 09-19-2024, 06:37 AM
w64bit w64bit is offline Replace font in Normal Style Windows 10 Replace font in Normal Style Office 2021
Novice
Replace font in Normal Style
 
Join Date: Jan 2015
Posts: 19
w64bit is on a distinguished road
Default

Huge thanks to all.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a text style which only changes the font and font size? Jenson Word 3 03-04-2024 02:54 AM
Replace font in Normal Style Check the font attached to a template's "Normal" style and report if it's not installed Matt C Word VBA 3 10-31-2021 05:54 AM
Replace font in Normal Style Replace table and figure caption style to another style Word VBA laith93 Word VBA 7 08-27-2021 11:37 PM
Change Normal Style JohnM Word 2 03-23-2016 07:40 AM
Replace font in Normal Style Outlook2013 Normal Style sus4n Outlook 3 08-07-2014 06:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft