Apply Text Formatting to All Tables in Word with One Click Using VBA

When you’re working in a Microsoft Word document with many tables and you want to change the text formatting (such as font size, family, weight, etc.) of all tables at once, doing it manually for each table can be time consuming and challenging. In this blog post I will show you how to automate this process using VBA code, so you will be able to change the text formatting of all tables in Word document with one click.

In this example I will change the font size, family, and color of the text in all tables

Click here to learn more about text formatting using VBA

  1. Open VBA Editor By Pressing Alt + F11.
  1. Insert a new module by clicking Insert > Module.
Text formatting all tables in Word using VBA
  1. Copy and paste one of the following VBA subroutine codes into the module, then press Ctrl+S to save and close the VBA Editor

Text formatting of all tables

Sub tablesTextFormatting()
      Dim wdTable As Table
      For Each wdTable In ActiveDocument.Table
           wdTable.Range.Font.Size = 14
           wdTable.Range.Font.Name = "Arial"
           wdTable.Range.Font.TextColor = RGB(255, 0, 255)
      Next wdTable
 End Sub

Text Formatting of First Row (or Any Row) of All Tables

Sub tablesFirstRowsFormatting()
      Dim wdTable As Table
      For Each wdTable In ActiveDocument.Tables
           wdTable.Rows(1).Select
           Selection.Font.Size = 14
           Selection.Font.Name = "Arial"
           Selection.Font.TextColor = RGB(255, 0, 255)
      Next wdTable
 End Sub

Apply Text Formatting to First Column (or Any Column) of All Tables

Sub tablesFirstRowsFormatting()
      Dim wdTable As Table
      For Each wdTable In ActiveDocument.Tables
           wdTable.Columns(1).Select
           Selection.Font.Size = 14
           Selection.Font.Name = "Arial"
           Selection.Font.TextColor = RGB(255, 0, 255)
      Next wdTable
 End Sub

Clearing the text formatting

Below is a simple VBA code that removes text formatting (such as font, size, bold, italics, color, etc.) from all tables in the active document.

Sub resetTextFormattingofAlltables()
   Dim wdTable As Table
      For Each wdTable In ActiveDocument.Tables
           wdTable.Range.Font.Reset
      Next wdTable
 End Sub
  1. To Execute your VBA Code Press Alt + F8, select your created VBA, and click on Run Button.

Click Here to to learn More about how to use and run VBA Code in Word

I hope this tutorial will helps you to Apply Text Formatting to All Tables in Word with One Click Using VBA code. If you have any question, suggestion or feedback feel free to contact us using the details provided on our contact us page.

Thank you for your feedback and support.

Similar Posts