Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-28-2012, 03:41 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline How to select the first row of the current table Windows XP How to select the first row of the current table Office 2007
Competent Performer
How to select the first row of the current table
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

I think I got it. Here's the macro. It changes three settings:
  • It turns off the Break Across Pages setting (for rows).
  • It turns off the Auto Fit setting (for columns).
  • It set row 1 as a header row if the user says "Yes".
Here's the code. Comments appreciated.

Code:
'===========================================================================
'                        My Table Settings
' Correct the table settings to what Word should have made them.
' 07/23/10  Recorded and modified.
' 01/28/12  Add code for header row
'===========================================================================
Sub MyTableSettings()
Const MyName = "MyTableSettings"
Dim SettingBreakOld                 'Old setting
Dim SettingAutoFitOld               'Old setting
Dim SettingHeaderRow As Boolean     'True = set first row as header
Dim SettingHeaderRowOld As Boolean  'Old setting
Dim Msg
'Abort if the cursor is not in a table
If Selection.Information(wdWithInTable) <> True Then
  MsgBox "The cursor is not in a table", vbOKOnly, MyName
  Exit Sub
End If
 
'Ask if they want a header row?
Select Case MsgBox("Set row 1 as header?", vbYesNoCancel, MyName)
  Case vbYes
    SettingHeaderRow = True
  Case vbNo
    SettingHeaderRow = False
  Case vbCancel
    MsgBox "Aborted", vbOKOnly, MyName
    Exit Sub
End Select
'Save old settings
SettingBreakOld = Selection.Rows.AllowBreakAcrossPages
If SettingBreakOld = -1 Then   '-1 = On, 0 = Off
  SettingBreakOld = "On"
ElseIf SettingBreakOld = 0 Then
  SettingBreakOld = "Off"
End If
SettingAutoFitOld = Selection.Tables(1).AllowAutoFit
If SettingAutoFitOld = "True" Then   'True = On, False = Off
  SettingAutoFitOld = "On"
ElseIf SettingAutoFitOld = "False" Then
  SettingAutoFitOld = "Off"
End If
SettingHeaderRowOld = Selection.Tables(1).Rows(1).HeadingFormat
'Set the new ones
Selection.Tables(1).Select                                    'Select the entire table
Selection.Rows.AllowBreakAcrossPages = False                  'Stop rows from breaking
Selection.Tables(1).AllowAutoFit = False                      'Stop auto-resizing
Selection.Tables(1).Rows(1).HeadingFormat = SettingHeaderRow  'Set the heading setting
'Report the results
Msg = "Autofit = Off (was " & SettingAutoFitOld & "), " & vbCrLf & _
      "Break = Off (was " & SettingBreakOld & "), " & vbCrLf & _
      "Header row = " & SettingHeaderRow & " (was " & SettingHeaderRowOld & ")"
MsgBox Msg, vbOKOnly, MyName
End Sub
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to select the first row of the current table How to call current PC date and/or current PC year KIM SOLIS Excel 2 11-04-2011 06:09 PM
How to select the first row of the current table Select Text in Table but Table Gets Selected Too RBusiness Word 1 06-07-2011 04:26 PM
How to select the first row of the current table Access to the property of the current table b0x4it Word VBA 2 05-26-2011 06:25 AM
Table - Check Boxes - Create Select All lajohn1963 Word Tables 2 09-25-2010 11:18 AM
How to select the first row of the current table Auto insert current month's name and current year Styler001 Word 4 01-25-2010 06:40 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft