T
Tom
I have two types of tables in my document -- one for reference
information, and one for notes, cautions, etc. The former tables have
borders, but the latter do not.
I currently have a macro that formats all tables with a specific
format.
How would I make it so that the macro only formats one type of tables
in my document? In other words, so that it formats reference tables
with borders, and note tables without borders?
Here's the macro (actually from Peter Grainge's site) that I'm using to
format all tables:
Sub FormatTablesAll()
' Runs through all tables in the document and applies the properties
defined.
' Does not give user option to skip a table.
' This starts the macro at the start of the document
Selection.HomeKey Unit:=wdStory
'This declares the variable that counts the number of tables.
Dim iNumber As Integer
iNumber = ActiveDocument.Tables.Count
' This stops the macro running if there are no tables
If iNumber = 0 Then
MsgBox "There are no tables in this document"
End
Else
'This declares the variable that numbers the current table.
Dim iCurrent As Integer
For iCurrent = 1 To iNumber
' This finds the next table
Selection.GoTo what:=wdGoToTable, which:=wdGoToNext, Count:=1, Name:=""
' This selects the table
With Selection
.SelectColumn
.SelectRow
End With
' This formats the table
With Selection.Tables(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
' Enter other requirements here
End With
Selection.Collapse
' This loops to the next table until all the tables have been
processed.
Next iCurrent
End If
MsgBox "All tables have been formatted."
End Sub
Thanks for your help.
information, and one for notes, cautions, etc. The former tables have
borders, but the latter do not.
I currently have a macro that formats all tables with a specific
format.
How would I make it so that the macro only formats one type of tables
in my document? In other words, so that it formats reference tables
with borders, and note tables without borders?
Here's the macro (actually from Peter Grainge's site) that I'm using to
format all tables:
Sub FormatTablesAll()
' Runs through all tables in the document and applies the properties
defined.
' Does not give user option to skip a table.
' This starts the macro at the start of the document
Selection.HomeKey Unit:=wdStory
'This declares the variable that counts the number of tables.
Dim iNumber As Integer
iNumber = ActiveDocument.Tables.Count
' This stops the macro running if there are no tables
If iNumber = 0 Then
MsgBox "There are no tables in this document"
End
Else
'This declares the variable that numbers the current table.
Dim iCurrent As Integer
For iCurrent = 1 To iNumber
' This finds the next table
Selection.GoTo what:=wdGoToTable, which:=wdGoToNext, Count:=1, Name:=""
' This selects the table
With Selection
.SelectColumn
.SelectRow
End With
' This formats the table
With Selection.Tables(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.Color = RGB(0, 0, 0)
End With
' Enter other requirements here
End With
Selection.Collapse
' This loops to the next table until all the tables have been
processed.
Next iCurrent
End If
MsgBox "All tables have been formatted."
End Sub
Thanks for your help.