title: I want to set spacing to single for all tables in Word 2007 document
body: <p>I have an exported Word document in which tables constructed by a database extractor have space between wrapped lines in cells that I can remove by selecting the table and using the paragraph dialog box, but there are many tables and I want to automate this.</p>
  
  <p>All I have to do after selecting all the tables in the document (which I can do with VBA) is set Add Space Before and Add Space After both = 0, which I think, secretly also sets the <code>AddSpaceBeforeAuto = AddSpaceAfterAuto = False</code>.</p>
  
  <p>So I started with a simple select subroutine: </p>
  
  <pre><code>Sub selecttables()    
      Dim mytable As Table   
      Application.ScreenUpdating = False
  
      For Each mytable In ActiveDocument.Tables
      mytable.Range.Editors.Add wdEditorEveryone    
      Next    
      ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)   
      ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)   
      Application.ScreenUpdating = True 
  End Sub
  </code></pre>
  
  <p>This works fine and leaves all my tables selected. All I want to do now is set the appropriate ParagraphFormat members to mimic my setting of these properties in the Paragraph Dialog to zero and false. </p>
  
  <p>I tried three approaches:
  1. Set the values globally for the Normal style (which all the tables use)
  2. Set the values for each table as they are selected
  3. Set the values on the total selection, after all the tables are selected.</p>
  
  <p>When I do this manually after <code>selecttables()</code> executes, I am doing method 3.</p>
  
  <p>The function below actually tries all three methods. I have selectively commented them out and discovered that no one of the methods works and doing all three doesn't help any. </p>
  
  <p>I tried both "With Selection.Range.Style.ParagraphFormat"   and "With Selection.Range.ParagraphFormat" for METHOD 3, but neither worked.</p>
  
  <p>I would also like to set the table property, "Allow row to break across pages" to False (because, seriously, the default value of True is really dumb!) and can't figure how to do that either.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>Sub FixTables()
     Dim mytable As Table
     Dim i As Integer
     Application.ScreenUpdating = False
  '  METHOD 1:
     ActiveDocument.Styles("Normal").ParagraphFormat.Space1
     ActiveDocument.Styles("Normal").ParagraphFormat.SpaceAfter = 0
     ActiveDocument.Styles("Normal").ParagraphFormat.SpaceBefore = 0
     ActiveDocument.Styles("Normal").ParagraphFormat.SpaceAfterAuto = False
     ActiveDocument.Styles("Normal").ParagraphFormat.SpaceBeforeAuto = False
  
  For Each mytable In ActiveDocument.Tables
  '   METHOD 2:
      With mytable.Style.ParagraphFormat
          .Space1
          .SpaceBefore = 0
          .SpaceBeforeAuto = False
          .SpaceAfter = 0
          .SpaceAfterAuto = False
      End With
      mytable.Range.Editors.Add wdEditorEveryone
  Next
  
  ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
  ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
  '
      With Selection.Style.ParagraphFormat
          .SpaceBefore = 0
          .SpaceBeforeAuto = False
          .SpaceAfter = 0
          .SpaceAfterAuto = False
      End With
      Application.ScreenUpdating = True
  End Sub
  </code></pre>