View Single Post
 
Old 01-28-2012, 07:03 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Jennifer,

Your code could be simplified a bit. In particular, there's no need to select the whole table before working on it. Aside from executing faster, not selecting it has the advantage of leaving the selected range unchanged:
Code:
Sub MyTableSettings()
Const MyName = "MyTableSettings"
Dim SettingBreakOld                 'Old setting
Dim SettingAutoFitOld               'Old setting
Dim SettingHeaderRowOld As Boolean  'Old setting
Dim Msg
'Abort if the cursor is not in a table
If Selection.Information(wdWithInTable) = False Then
  MsgBox "The cursor is not in a table", vbOKOnly, MyName
  Exit Sub
End If
'Save old settings
With Selection.Tables(1)
  SettingBreakOld = (.Rows.AllowBreakAcrossPages = True)
  SettingAutoFitOld = (.AllowAutoFit = True)
  SettingHeaderRowOld = (.Rows(1).HeadingFormat = True)
  'Set the new ones
  .Rows.AllowBreakAcrossPages = False                  'Stop rows from breaking
  .AllowAutoFit = False
  'Ask if they want a header row?
  Select Case MsgBox("Set row 1 as header?", vbYesNoCancel, MyName)
    Case vbYes
      .Rows(1).HeadingFormat = True
    Case vbNo
      .Rows(1).HeadingFormat = False
    Case vbCancel
      MsgBox "Aborted", vbOKOnly, MyName
      Exit Sub
  End Select
  'Report the results
  Msg = "Autofit = True (was " & SettingAutoFitOld & "), " & vbCrLf & _
      "Break = True (was " & SettingBreakOld & "), " & vbCrLf & _
      "Header row = " & (.Rows(1).HeadingFormat = True) & " (was " & SettingHeaderRowOld & ")"
  MsgBox Msg, vbOKOnly, MyName
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote