Sub AdjustTableWidths()
Dim doc As Document
Dim tbl As Table
Dim tblWidth As Single
Dim docWidth As Single
Set doc = ActiveDocument
docWidth = doc.PageSetup.PageWidth - doc.PageSetup.LeftMargin - doc.PageSetup.RightMargin
For Each tbl In doc.Tables
tblWidth = tbl.PreferredWidth
If tblWidth > docWidth Then
tbl.PreferredWidth = docWidth
tbl.AllowAutoFit = False ' Prevent autofit to ensure width stays as set
' Optionally, you can adjust column widths proportionally
Dim col As Column
Dim totalColWidth As Single
totalColWidth = 0
' Calculate total width of columns
For Each col In tbl.Columns
totalColWidth = totalColWidth + col.Width
Next col
' Adjust each column proportionally
For Each col In tbl.Columns
col.Width = col.Width * docWidth / totalColWidth
Next col
End If
Next tbl
End SubTuesday, December 24, 2024
VBA Word - Adjust Table alignment in middle of document
The following VBA code adjusts table alignment in middle of document:
Subscribe to:
Post Comments (Atom)
Hot Topics
-
In the previous post we have learnt about SSMS (SQL Server Management Studio) and how to connect with a SQL Server instance. In this post w...
-
By Ajeet Kumar RADAR CHART In radar chart, the categorical variable is displayed as spikes radiating from a central point. The values o...
-
In previous post , we learnt basic introduction to SQL Server . In this post we will learn about SSMS (SQL Server Management Studio) softwar...
No comments:
Post a Comment