Wednesday, June 25, 2025

Macro VBA script: Change 1st column width for all table

 Sub SetFirstColumnWidthInPicas()

    Dim tbl As Table

    Dim r As Long

    Dim desiredWidthPicas As Single

    Dim desiredWidthPoints As Single


    ' Set desired width in picas

    desiredWidthPicas = 30 ' ? Change this as needed

    desiredWidthPoints = desiredWidthPicas * 12 ' Convert picas to points


    For Each tbl In ActiveDocument.Tables

        With tbl

            For r = 1 To .Rows.Count

                On Error Resume Next ' In case cell doesn't exist (e.g. merged)

                With .cell(r, 1)

                    .Width = desiredWidthPoints

                End With

                On Error GoTo 0

            Next r

        End With

    Next tbl


    MsgBox "First column width updated to " & desiredWidthPicas & " picas.", vbInformation

End Sub

No comments:

Post a Comment