title: Table AutoFitBehavior does not work in Word Document
body: <p>i am trying to develop a print function in my Java Swing Desktop Application. All i need is a basic printing, so there is no need of an external library or something. My app, is only for windows, so there is nothing to stop me for using a VBS file in order to generate a Word (.docx) document and just print it.</p>
  
  <p>The thing is that i need to print a table. My app generates, the following script (ignore the fields, texts and etc).</p>
  
  <pre><code>Set objWord = CreateObject("Word.Application")
  Set objDoc = objWord.Documents.Add()
  objWord.Visible = False
  Set objSelection = objWord.Selection
  
  Set objSection = objDoc.Sections(1)
  objDoc.Sections(1).Footers(1).Range.ParagraphFormat.Alignment = 0
  objDoc.Sections(1).Footers(1).Range.Bold = True
  objDoc.Sections(1).Footers(1).Range.Text = ""
  
  
  objSelection.Font.Bold = True
  objSelection.Font.Underline = True
  objSelection.ParagraphFormat.Alignment = 1
  objSelection.Font.Size = "14"
  objSelection.TypeText "I am a title"
  objSelection.TypeParagraph()
  objSelection.Font.Underline = False
  
  objSelection.Font.Size = "12"
  Const NUMBER_OF_ROWS = 2
  Const NUMBER_OF_COLUMNS = 4
  Set objRange = objDoc.Range()
  objrange.Collapse wdCollapseEnd 
  objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
  Set objTable = objDoc.Tables(1)
  objTable.Style = "Πλέγμα Πίνακα" 'Greek MS Word needs style name on greek. "Table Grid" is the english one
  objTable.Cell(1, 1).Range.Text = "Description"
  objTable.Cell(1, 2).Range.Text = "Date"
  objTable.Cell(1, 3).Range.Text = "Count"
  objTable.Cell(1, 4).Range.Text = "Notes"
  
  
  objTable.Cell(2, 1).Range.Text = "Hello there i am"+Chr(13)+"a big text"+Chr(13)+"but i am far bigger than you"
  objTable.Cell(2, 2).Range.Text = "10/11/2018"
  objTable.Cell(2, 3).Range.Text = "10.000"
  objTable.Cell(2, 4).Range.Text = "nothing here"
  
  objSelection.Tables(1).Select
  objSelection.Collapse wdCollapseEnd
  
  objDoc.SaveAs("C:\Users\George\AppData\Local\Temp\AAA - 13213908551013013192846.docx")
  
  objWord.Quit
  </code></pre>
  
  <p>With this script, i get <a href="https://i.stack.imgur.com/qcOyu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qcOyu.png" alt="this table"></a></p>
  
  <p>What i want to achieve is: <a href="https://i.stack.imgur.com/SpxoX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SpxoX.png" alt="this."></a></p>
  
  <p>In order to get the table which is in the second image, i did the following steps from MS Word. <em>Right click in the table - > Auto Adjust - > Auto Adjust with the contents</em>, then again, <em>Right click in the table - > Auto Adjust -> Auto Adjust in the window</em>.</p>
  
  <p>So, i guessed recording these steps via "Create Macro" action from MS Word will give me the answer. It "gave" me these lines:</p>
  
  <pre><code>objSelection.Tables(1).AutoFitBehavior (wdAutoFitContent)
  objSelection.Tables(1).AutoFitBehavior (wdAutoFitWindow)
  </code></pre>
  
  <p>I added them in my script, right before "Save as..." but there is not any changes to the table. So....I was wondering, is there anything more should i  do, or do i do something wrong? I am not familiar with VBA.</p>
  
  <p>OS: Windows 10 x64</p>
  
  <p>MS-Office: Microsoft Office Professional Plus <strong>2016</strong></p>
  
  <p><strong>EDIT - Answer</strong>:</p>
  
  <pre><code>objSelection.Tables(1).AutoFitBehavior (1) 'word VBA does not support enumerations
  objSelection.Tables(1).Rows.Alignment = 1
  </code></pre>