How to change font and font size in all text boxes in a Word document?

This article addresses the process of changing the font and font size within text boxes in the current document or multiple documents within a specified folder. Let’s explore the VBA method outlined in this article.

Change font and font size in text boxes in the current document

To change the font and font size within text boxes in the current document, please apply the following VBA code to resolve the issue:

1. Press Alt + F11 to open the Microsoft Visual Basic for Application window.

2. In the Microsoft Visual Basic for Application window, click Insert > Module, then copy the following code into the Module window.

VBA Code: Change font and font size in all text boxes in the current document

Sub FormatTextsInTextBoxes()
‘Updated by ExtendOffice 20181128
Dim I As Long
Dim xShape As Shape
Dim xDoc As Document
Set xDoc = ActiveDocument
On Error Resume Next
For Each xShape In xDoc.Shapes
xShape.Select
If xShape.GroupItems Is Nothing Then
With xShape.TextFrame.TextRange.Font
.Name = “Arial”
.Size = 20
End With
GoTo LblExit
End If
For I = 1 To xShape.GroupItems.Count
With xShape.GroupItems(I).TextFrame.TextRange.Font
.Name = “Arial”
.Size = 20
End With
Next
LblExit:
Next
End Sub

Note: In the code, “Arial” and “20” are the specified font and font size in my case. You can change them based on your own needs.

3. Press F5 to run the code. Afterwards, the font and font size of all text within the text boxes will be changed to the specified font and font size.

How to change font and font size in all text boxes in a Word document

How to change font and font size in all text boxes in a Word document

Change font and font size in text boxes of all documents in a folder

To change the font and font size of text boxes in multiple Word documents, you need to apply the following VBA code:

1. Collect all target documents containing text boxes that you want to modify within the same folder.

2. In the open Word document, press Alt + F11 to open the Microsoft Visual Basic for Application window.

3. In the Microsoft Visual Basic for Application window, click Insert > Module, then copy the following code into the Module window.

VBA Code: Change font and font size in text boxes of multiple documents

Sub FormatTextsInTextBoxesInMultiDoc()
‘Updated by ExtendOffice 20181128
Dim I As Long
Dim xShape As Shape
Dim xDlg As FileDialog
Dim xFolder As Variant
Dim xFileStr As String
On Error Resume Next
Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
If xDlg.Show = -1 Then
xFolder = xDlg.SelectedItems(1) + “\”
xFileStr = Dir(xFolder & “*.doc”, vbNormal)
While xFileStr <> “”
Documents.Open xFolder & xFileStr
For Each xShape In ActiveDocument.Shapes
xShape.Select
If xShape.GroupItems Is Nothing Then
With xShape.TextFrame.TextRange.Font
.Name = “Arial”
.Size = 20
End With
GoTo LblExit
End If
For I = 1 To xShape.GroupItems.Count
With xShape.GroupItems(I).TextFrame.TextRange.Font
.Name = “Arial”
.Size = 20
End With
Next
LblExit:
Next
ActiveDocument.Save
ActiveDocument.Close
xFileStr = Dir()
Wend
End If
End Sub

4. Press F5 to run the code. In the open Browse window, select the folder (containing the documents in which you want to change the font and font size within the text boxes) and click OK.


Following these steps, the font and font size of all text boxes in the selected folder’s documents will be changed to the specified font and font size.

You have now learned how to efficiently change the font and font size in all text boxes within a Word document. You can apply these methods to streamline your workflow, save time, and enhance productivity. If you encounter any issues or have any other specific requests, please don’t hesitate to reach out for further assistance. Best of luck with your document!

We will be happy to hear your thoughts

Leave a reply

Gotkey.net
Logo
Compare items
  • Total (0)
Compare
0
Shopping cart