Question & Answer
Question
How do I Control Table Columns Width in a generated document?
Answer
The column width of the table can be controlled by using VBA Macro as there is no method directly from within ReporterPlus.
Method 1: (% as desired for the columns)
The macro below adjusts the table width of fourth column.
First column width to 10%
Second column width to 30%
Third column width to 30%
Fourth column width to 30%
///////////////////////////////////////////////////////////////////////////////////////
Sub ChangeTableWidth()
Dim objTable As Table
Dim tablewidth as integer
For Each objTable In ActiveDocument.Tables
tablewidth = 0
For CellNo = 1 To objTable.Rows(1).Cells.Count
tablewidth = tablewidth + objTable.Rows(1).Cells(CellNo).Width
Next CellNo
objTable.Columns(1).Width = tablewidth * 0.1 '0.1 specifies 10% of the table width or you can ( multiply tablewidth with 10/100 ie tablewidth * 10/100)
objTable.Columns(2).Width = tablewidth * 0.3 '0.3 specifies 30% of the table width
objTable.Columns(3).Width = tablewidth * 0.3
objTable.Columns(4).Width = tablewidth * 0.3
Next
End Sub
///////////////////////////////////////////////////////////////////////////////////////
Method 2 : value of the column width
This macro can be used to specify the width of individual columns
///////////////////////////////////////////////////////////////////////////////////////
Sub ChangeTableWidth()
Dim objTable As Table
For Each objTable In ActiveDocument.Tables
objTable.Columns(1).Width = 25
objTable.Columns(2).Width = 50
objTable.Columns(3).Width = 100
objTable.Columns(4).Width = 100
Next
End Sub
///////////////////////////////////////////////////////////////////////////////////////
Method 3: Autofit to the content of the table
///////////////////////////////////////////////////////////////////////////////////////
Sub ChangeTableWidth()
Dim objTable As Table
For Each objTable In ActiveDocument.Tables
objTable.AutoFitBehavior wdAutoFitContent
Next objTable
End Sub
///////////////////////////////////////////////////////////////////////////////////////
To Place the macro:
- Open a model in Rhapsody.
- Select Tools-> VBA -> Macro.
- Go to Insert Menu and select Module
-
Paste the macro and save by clicking save button in the toolbar
To run the macro:
1. Run the macro by selecting Tools -> VBA->Macro -> macroname after generating the document.
7.1 MR1,7.1 MR2,7.1 MR3AnswerProduct versionPartner ContentInternal ContentCategoryReference IDAuthor
[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Version Independent","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]
Historical Number
40224
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21324336