phil1429
asked on
Macro to replace bullet char with bullet style and keep paragraph text bold
Word 2003 macro
I'm replacing a bullet char with the List Bullet Style. My macro works, but the text of the paragraph is bold. After I run my macro the text is no longer bold. Can you show me how to change the macro to keep the paragraph text bold?
Sub ConvertBulletChar()
Const BulletStyle As String = "List Bullet"
Dim Para As Paragraph
Dim BulletChar As String
Dim s As String
BulletChar = Chr$(149)
With ActiveDocument
For Each Para In .Paragraphs
With Para
s = Mid$(.Range.Text, 1, 1)
If InStr(1, BulletChar, s) Then
.Style = BulletStyle
End If
End With
Next
End With
End Sub
I'm replacing a bullet char with the List Bullet Style. My macro works, but the text of the paragraph is bold. After I run my macro the text is no longer bold. Can you show me how to change the macro to keep the paragraph text bold?
Sub ConvertBulletChar()
Const BulletStyle As String = "List Bullet"
Dim Para As Paragraph
Dim BulletChar As String
Dim s As String
BulletChar = Chr$(149)
With ActiveDocument
For Each Para In .Paragraphs
With Para
s = Mid$(.Range.Text, 1, 1)
If InStr(1, BulletChar, s) Then
.Style = BulletStyle
End If
End With
Next
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's great and I like how you got rid of the original bullet. I was removing it later with much less finesse. My final job on these bullets is to change the format. Now, this part of my macro removes the bold text of the paragraph. Any more great ideas? Also, this document comes from Crystal Reports. I can have the designer in Crystal do something different with the bullets. Should I ask for the bullets as an asterisk and take advantage of autoformatting?
Sub SetBulletStyle()
Dim oLT As ListTemplate
Dim oLL As ListLevel
For Each oLT In ActiveDocument.ListTemplat es
With oLT
For Each oLL In oLT.ListLevels
If oLL.NumberStyle = wdListNumberStyleBullet Then
With oLL
.NumberFormat = ChrW(61607)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.TabPosition = InchesToPoints(0.25)
.ResetOnHigher = 0
.StartAt = 1
.Font.Name = "Wingdings"
.LinkedStyle = "List Bullet"
End With
End If
Next oLL
Next oLT
End Sub
Sub SetBulletStyle()
Dim oLT As ListTemplate
Dim oLL As ListLevel
For Each oLT In ActiveDocument.ListTemplat
With oLT
For Each oLL In oLT.ListLevels
If oLL.NumberStyle = wdListNumberStyleBullet Then
With oLL
.NumberFormat = ChrW(61607)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.TabPosition = InchesToPoints(0.25)
.ResetOnHigher = 0
.StartAt = 1
.Font.Name = "Wingdings"
.LinkedStyle = "List Bullet"
End With
End If
Next oLL
Next oLT
End Sub
ASKER
I got it. I just left out the .LinkedStyle = "List Bullet" line, but any improvements would be appreciated.
Sub SetBulletStyle()
Dim oLT As ListTemplate
Dim oLL As ListLevel
For Each oLT In ActiveDocument.ListTemplat es
For Each oLL In oLT.ListLevels
If oLL.NumberStyle = wdListNumberStyleBullet Then
With oLL
.NumberFormat = ChrW(61607)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.TabPosition = InchesToPoints(0.25)
.ResetOnHigher = 0
.StartAt = 1
.Font.Name = "Wingdings"
End With
End If
Next oLL
Next oLT
End Sub
Sub SetBulletStyle()
Dim oLT As ListTemplate
Dim oLL As ListLevel
For Each oLT In ActiveDocument.ListTemplat
For Each oLL In oLT.ListLevels
If oLL.NumberStyle = wdListNumberStyleBullet Then
With oLL
.NumberFormat = ChrW(61607)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.25)
.TabPosition = InchesToPoints(0.25)
.ResetOnHigher = 0
.StartAt = 1
.Font.Name = "Wingdings"
End With
End If
Next oLL
Next oLT
End Sub
I think the change is to do with the format of the ListBullet style. I suggest you go to Format, Style and then check the settings for List Bullet Style, and change formatting to bold.
Hope this helps
Denis