VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Susanto3311 »

hi expert..

I am looking for VBA code in MS Word to make numbered list (bullet & numbering) in a Word document same font & same font size
often, when select all document then change font & size for NUMBERING LIST not change it (different font & size).
i want the VBA code work with step like this:
1. first time, when running vba, automatic select all document/paragraph then simultan automatically change font & size to be ARIAL font with Size 11 (include numbering list)
2. the vba code can work/save as MS Word Add-Ins.

here attachment picture more detail information

susanto
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by HansV »

Does this do what you want?

Code: Select all

Sub ChangeFont()
    With ActiveDocument.Content.Font
        .Name = "Arial"
        .Size = 11
    End With
End Sub
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Susanto3311 »

hi Hans, thank but fully work.
if document contains bullet & numbered (numbered list) the font can't change (name font & size font not change)..

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by HansV »

Sorry, I don't understand that. Do you mean that the code does not change the numbering font (it does when I run the macro) or that it should leave the numbering font unchanged?

(I won't reply soon - it's after midnight here)
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Susanto3311 »

ok, Hans, Good Night.
when i run the macro, all document change font & size, only list font of number e.g.1,2,3,4,etc...unchanged.
no matter you should take a rest.

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Susanto3311 »

here new attachment
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by HansV »

Try this:

Code: Select all

Sub ChangeFont()
    Dim par As Paragraph
    With ActiveDocument.Content.Font
        .Name = "Arial"
        .Size = 11
    End With
    For Each par In ActiveDocument.ListParagraphs
        With par.Range.ListFormat.ListTemplate.ListLevels(1).Font
            .Name = "Arial"
            .Size = 11
        End With
    Next par
End Sub
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Susanto3311 »

hi Hans, thank you. Working perfect!!!

User avatar
Charles Kenyon
5StarLounger
Posts: 615
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Charles Kenyon »

Much better, though, in my opinion, is to utilize styles. Attach your numbering to existing paragraph styles, perhaps base those styles on a basic Body Text style, and simply change the font used in the Body Text style. Everything else falls in line. See how styles in Microsoft Word Cascade by Word MVP Shauna Kelly. http://shaunakelly.com/word/styles/hows ... scade.html

If you are doing much of your formatting as Direct Formatting rather than through styles, you are shooting yourself in the foot. You are making more work and more frustration for yourself. This is true with vba as well as manually. http://www.addbalance.com/usersguide/st ... m#Overview

Jakov93
NewLounger
Posts: 9
Joined: 26 Feb 2024, 21:56

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Jakov93 »

HansV wrote:
25 Feb 2022, 08:32
Try this:

Code: Select all

Sub ChangeFont()
    Dim par As Paragraph
    With ActiveDocument.Content.Font
        .Name = "Arial"
        .Size = 11
    End With
    For Each par In ActiveDocument.ListParagraphs
        With par.Range.ListFormat.ListTemplate.ListLevels(1).Font
            .Name = "Arial"
            .Size = 11
        End With
    Next par
End Sub
Dear Hans,
I want to change the font and size for all list levels, but not just level 1, what I do, please?
Thanks

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by HansV »

Welcome to Eileen's Lounge!

Do you want to set the same font name and size for all levels, or do you want to set them for each level individually?
Best wishes,
Hans

Jakov93
NewLounger
Posts: 9
Joined: 26 Feb 2024, 21:56

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Jakov93 »

HansV wrote:
27 Feb 2024, 07:50
Welcome to Eileen's Lounge!
Thanks so much
Thanks for your helpful forum
HansV wrote:
27 Feb 2024, 07:50
Do you want to set the same font name and size for all levels, or do you want to set them for each level individually?
Yes, the same font and size for all levels
if I want to set each level individually, I think I will use this line to do that

Code: Select all

With par.Range.ListFormat.ListTemplate.ListLevels(n).Font

n= certain level
Thanks again

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by HansV »

See if this does what you want.

Code: Select all

Sub ChangeFont()
    Dim par As Paragraph
    Dim n As Long
    With ActiveDocument.Content.Font
        .Name = "Arial"
        .Size = 11
    End With
    For Each par In ActiveDocument.ListParagraphs
        With par.Range.ListFormat
            n = .ListLevelNumber
            With .ListTemplate.ListLevels(n).Font
                .Name = "Arial"
                .Size = 11
            End With
        End With
    Next par
End Sub
Best wishes,
Hans

Jakov93
NewLounger
Posts: 9
Joined: 26 Feb 2024, 21:56

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by Jakov93 »

HansV wrote:
27 Feb 2024, 15:42
See if this does what you want.

Code: Select all

Sub ChangeFont()
    Dim par As Paragraph
    Dim n As Long
    With ActiveDocument.Content.Font
        .Name = "Arial"
        .Size = 11
    End With
    For Each par In ActiveDocument.ListParagraphs
        With par.Range.ListFormat
            n = .ListLevelNumber
            With .ListTemplate.ListLevels(n).Font
                .Name = "Arial"
                .Size = 11
            End With
        End With
    Next par
End Sub
Thanks so much
It works perfectly

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by HansV »

You're welcome!
Best wishes,
Hans

snb
4StarLounger
Posts: 574
Joined: 14 Nov 2012, 16:06

Re: VBA:Make Font, Size, Numbered List Same Format (Arial 11)

Post by snb »

Use Word's builtin options:

Code: Select all

Sub M_snb()
   With ActiveDocument.ListTemplates(1)
      .Name = "snb"
      .ListLevels(1).Font.Name = "Arial"
      .ListLevels(1).Font.Size = 11
    End With
End Sub