title: Word VBA script behaves differently when launched with "Step-into" or "Run"
body: <p>This is my first attempt at writing a VBA script for Word (I'm an ex-programmer who's had reasonable, self-taught, success with Excel VBA). I'm using Word 2013 (15.0.4641.1001 64-bit) and VBA 7.1 .142.</p>
  
  <p>I'm trying to perfom a simple task, which is to create a two-column table at the current cursor position (which itself can be inside another table). I want the table to be 100% of the width available  to it, then I want to fix the width of the first column. Essentially, my code does what I want (and for a first attempt, I'm reasonably pleased with it), but it's erratic.</p>
  
  <p>The problems relate to the widths. If I position the cursor and "Step-into" the macro, it normally (90%+ of the time) does what I want. If I "Run" it, it never works correctly.</p>
  
  <p>My code is given below. What it's supposed to do is this:-</p>
  
  <ol>
  <li>Create a table 5 rows x 2 columns, that is the full width of wherever it's located.</li>
  <li>Make the first column a fixed width (to accept a short, fixed-format string)</li>
  <li>Sequentially number each row and right-justify the text.</li>
  <li>Split column two into two rows per original row.</li>
  </ol>
  
  <p>The problem is with action "2", the others work ok.</p>
  
  <ul>
  <li>If the table is full-document width, action "2" in "Step into" seems to always work correctly, however</li>
  <li>When it is "Run", action "2" always fails by making the first column 50% wide.</li>
  <li>If I manually create a 1-row by 2-column table and then "Step into" the macro to create a sub-table in each of its two cells :
  
  <ul>
  <li>action "2"  for the first sub-table works correctly, but</li>
  <li>action "2"  for the second sub-table usually sets the first column to 50% instead of fixed width</li>
  <li>Sometimes action "2" sets the whole sub-table to be 50% of the width of its parent cell, and sets both its columns to be 50% of its own width</li>
  </ul></li>
  </ul>
  
  <p>One thing I have noticed is that when it executes, the command</p>
  
  <pre><code>     .Columns(1).PreferredWidth = 15
  </code></pre>
  
  <p>seems to take noticably longer than other commands.</p>
  
  <p>As I said, this is my first effort and I don't yet know enough to be aware of whether or not I've overlooked some parameter somewhere.</p>
  
  <p>I'd be really grateful if somebody can explain where I'm going wrong and how it can be fixed.</p>
  
  <p>Cheers</p>
  
  <p>Baz</p>
  
  <p>Here's my code.</p>
  
  <pre><code>Sub CreateTable()
  AddRows = 5
  Set NewTable = ActiveDocument.Tables.Add(Selection.Range, AddRows, 2)
  With NewTable
  'Display cell borders
      If .Style &lt;&gt; "Table Grid" Then
          .Style = "Table Grid"
      End If
  'Make table 100% wide
      .PreferredWidthType = wdPreferredWidthPercent
      .PreferredWidth = 100
  'Make column 1 narrow
      .PreferredWidthType = wdPreferredWidthPoints
      .Columns(1).PreferredWidth = 15
      .AutoFitBehavior (wdAutoFitFixed)
  'Number each row
      For a = 1 To AddRows
          .Cell(a, 1).Range.InsertAfter a &amp; ")"
          .Cell(a, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphRight
      Next a
  'Split column 2
      For a = 1 To (AddRows * 2) - 1 Step 2
          .Cell(a, 2).Split NumRows:=2, NumColumns:=1
      Next a
  End With
  End Sub
  </code></pre>