PDA

View Full Version : Table Bullet and Table Number Macro have no Bullets or Numbers



Dave T
03-22-2012, 08:00 PM
Hello All,

I have been trying to get a macro by John McGhie to work.
His macro creates a three column table along with the following styles:

Table Body Text
Table Heading
Table Bullet
Table NumberAll of the macro work and creates the styles however the Table Bullet style does not have any bullets nor doe the Table Number style have any numbers.

Can anyone please explain why the following code does not work for me ???

Any comments appreciated.

Regards,
Dave T

Forgot to mention I am using Word 2003.



Option Explicit
Sub Main()
'http://www.mackb.com/Uwe/Forum.aspx/word/6159/Macro-for-table-problems
' Insert or Format Table Macro
' Macro recorded 14/03/00 by John McGhie
'
' On Error GoTo Error
Dim astyle As Style
Dim aDoc As String
Dim aTemplate As String
Dim x As Integer
Dim TabBodyText As Style
Dim TabHeading As Style
Dim TabBullet As Style
Dim tabNumber As Style
aTemplate = ActiveDocument.AttachedTemplate.FullName
aDoc = ActiveDocument.FullName
For Each astyle In ActiveDocument.Styles
If UCase(astyle.NameLocal) = UCase("Table Body Text") Then Set TabBodyText = astyle
If UCase(astyle.NameLocal) = UCase("Table Bullet") Then Set TabBullet = astyle
If UCase(astyle.NameLocal) = UCase("Table Heading") Then Set TabHeading = astyle
If UCase(astyle.NameLocal) = UCase("Table Number") Then Set tabNumber = astyle
Next astyle
If TabBodyText Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Body Text"
Set TabBodyText = ActiveDocument.Styles("Table Body Text")
With TabBodyText
.AutomaticallyUpdate = False
.BaseStyle = "Body Text"
.NextParagraphStyle = "Table Body Text"
End With
With TabBodyText.Font
'.Name = BodyFont
.Name = "Arial"
.Size = 10
.Bold = False
.Italic = False
End With
With TabBodyText.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 2
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = True
.PageBreakBefore = False
.FirstLineIndent = 0
.OutlineLevel = wdOutlineLevelBodyText
End With
End If
If TabHeading Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Heading"
Set TabHeading = ActiveDocument.Styles("Table Heading")
With TabHeading
.AutomaticallyUpdate = False
.BaseStyle = "Table Body Text"
.NextParagraphStyle = "Table Heading"
End With
With TabHeading.Font
'.Name = HeadingFont
.Name = "Arial"
.Size = 10
.Bold = True
.Italic = False
End With
With TabHeading.ParagraphFormat
.LeftIndent = 0
.RightIndent = 0
.SpaceBefore = 2
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = True
.KeepTogether = True
.PageBreakBefore = False
.FirstLineIndent = 0
.OutlineLevel = wdOutlineLevelBodyText
End With
End If
If TabBullet Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Bullet"
Set TabBullet = ActiveDocument.Styles("Table Bullet")
With TabBullet
.AutomaticallyUpdate = False
.BaseStyle = "Table Body Text"
.NextParagraphStyle = "Table Bullet"
End With
With TabBullet.Font
'.Name = BodyFont
.Name = "Arial"
.Size = 10
.Bold = False
.Italic = False
End With
With TabBullet.ParagraphFormat
.LeftIndent = 22
.RightIndent = 0
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 5
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.FirstLineIndent = -17
.OutlineLevel = wdOutlineLevelBodyText
End With
TabBullet.ParagraphFormat.TabStops.ClearAll
TabBullet.ParagraphFormat.TabStops.Add Position:=22, _
Alignment:=wdAlignTabLeft, _
Leader:=wdTabLeaderSpaces
With ListGalleries(wdBulletGallery).ListTemplates(7).ListLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = 6
.Alignment = wdListLevelAlignLeft
.TextPosition = 22
.TabPosition = 22
.ResetOnHigher = 0
.StartAt = 1
.Font.Name = "Symbol"
.LinkedStyle = "Table Bullet"
End With
End If
If tabNumber Is Nothing Then
ActiveDocument.Styles.Add Name:="Table Number"
Set tabNumber = ActiveDocument.Styles("Table Number")
With tabNumber
.AutomaticallyUpdate = False
.BaseStyle = "Table Bullet"
.NextParagraphStyle = "Table Number"
End With
With tabNumber.Font
'.Name = BodyFont
.Name = "Arial"
.Size = 10
.Bold = False
.Italic = False
End With
With tabNumber.ParagraphFormat
.LeftIndent = 22
.RightIndent = 0
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 2
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.FirstLineIndent = -17
.OutlineLevel = wdOutlineLevelBodyText
End With
tabNumber.ParagraphFormat.TabStops.ClearAll
tabNumber.ParagraphFormat.TabStops.Add Position:=22, _
Alignment:=wdAlignTabLeft, _
Leader:=wdTabLeaderSpaces
With ListGalleries(wdNumberGallery).ListTemplates(7).ListLevels(1)
.NumberFormat = "%1."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = 6
.Alignment = wdListLevelAlignLeft
.TextPosition = 22
.TabPosition = 22
.ResetOnHigher = 0
.StartAt = 1
.LinkedStyle = "Table Number"
End With
End If
If Not Selection.Information(wdWithInTable) Then
ActiveDocument.Tables.Add Range:=Selection.Range, _
NumRows:=5, _
NumColumns:=3, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitFixed
End If
Dim aTable As Table
Set aTable = Selection.Tables(1)
aTable.Select
aTable.AutoFormat Format:=wdTableFormatGrid5, _
ApplyBorders:=True, _
ApplyShading:=True, _
ApplyFont:=False, _
ApplyColor:=False, _
ApplyHeadingRows:=True, _
ApplyLastRow:=False, _
ApplyFirstColumn:=False, _
ApplyLastColumn:=False, AutoFit:=True
aTable.Select
With Selection
.Rows.AllowBreakAcrossPages = False
.Paragraphs.Reset
.Font.Reset
.Style = ActiveDocument.Styles("Table Body Text")
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth075pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderHorizontal)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderVertical)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
.Color = wdColorAutomatic
End With
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth025pt
.DefaultBorderColor = wdColorAutomatic
End With
aTable.Rows(1).Select
With Selection
.Style = ActiveDocument.Styles("Table Heading")
.Rows(1).HeadingFormat = True
With .Shading
.Texture = wdTexture10Percent
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorAutomatic
End With
End With
aTable.AutoFitBehavior (wdAutoFitWindow)
End
Error:
MsgBox "The Template has been damaged. See Tech Support.", vbCritical
End Sub

Dave T
03-22-2012, 09:05 PM
I also have another question about what to base styles upon.


Within the macro the styles are set up as follows:
'Table Body Text' is based on 'Body Text'
'Table Heading' is based on 'Table Body Text'
'Table Bullet' is based on 'Table Body Text'
'Table Number' is based on 'Table Bullet'Would there be any problems caused by basing the 'Table Number' style on the 'Table Bullet' style ???
Even if there were no problems should the 'Table Number' style be based upon the 'Table Body Text' style ???

Thanking you in advance for any comments.

fumei
03-22-2012, 11:37 PM
Generally, unless there is a clear need for a style relationship, I do not use parent-child cascades. I prefer to use no base styles.

"Would there be any problems caused by basing the 'Table Number' style on the 'Table Bullet' style ???"

There certainly could be. Again, that is why I use No base style, and make styles independent. As both numbers and bullets use that starting location, it seems to me to be a good idea to keep them separate.

Dave T
03-26-2012, 03:20 PM
Good to see you back Gerry,

I generally always set my styles to be based on 'none' so thanks for confirming this.

My original question was asking why the macro by John does not produce and bullets for the 'Table Bullet' style or any numbers for the "table Number' style.

When I go to Format > Styles and Formatting > Modify > Format > Numbering the highlighted selection for both styles shows 'None'.
Both styles have the paragraph set as 'hanging' by the size specified and a matching tab size, however the bullet and number is all that is missing.

I recorded a macro and added the following to the Table Bullet macro:

ActiveDocument.Styles("Table Bullet").LinkToListTemplate ListTemplate:= _
ListGalleries(wdBulletGallery).ListTemplates(4), ListLevelNumber:=1
This now adds a bullet and all looks OK (Note I also changed the List Template number in the macro to match the above).

Was this missing from John's original macro or have I just added unnecessary code ???

I also noted that if I change the indent and tab setting via the macro and re run the macro the setting do not change. I need to delete the four styles and re run the macro before the changes take place.

Does John's macro reset the specified list gallery and reapply the settings within the macro ???

Just trying to get my head around these concepts.

Regards,
Dave T

Dave T
03-26-2012, 03:41 PM
More follow up...

I have found that with the extra code I added, the Table Bullet (based of the Table Body Text style) now has a bullet.
If I leave the Table Number style based on the Table Bullet there are no numbers added, however if I use the Table Body text as a base style the numbers are now added.

Confusing.......