solracid
solracid

Reputation: 413

Set lists bulletpoint's style

I am setting some text as a list, and it displays with thick black dots. I am strugling to set the lists starting with "-" instead of dots.

Setting the list:

oDoc.Paragraphs.Add() '17
iStartIndex = oDoc.Paragraphs.Count
oDoc.Paragraphs.Last.Range.Text = strUmfang
iEndIndex = oDoc.Paragraphs.Count

oDoc.Range( Start := oDoc.Paragraphs(iStartIndex).Range.Start, End := 
oDoc.Paragraphs.Last.Range.End ).Select()

Selection.Range.ListFormat.ApplyBulletDefault

I tried to set with:

ListGalleries.Item(3).ListTemplates(1).ListLevels(1).NumberFormat = ChrW(61485)

It keeps displaying as black dots.

Upvotes: 0

Views: 658

Answers (2)

PeterT
PeterT

Reputation: 8557

I was able to record a macro that set up a new list style using the dash character. To create my test, I set up a blank document with 5 paragraphs of text:

enter image description here

Then, from the recorded macro, I created a separate Sub to initialize my new ListTemplate for a list style that uses a dash:

Private Function CreateCustomListStyle(ByRef oDoc As Document) As ListTemplate
    With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
        .NumberFormat = ChrW(8210)
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleBullet
        .NumberPosition = InchesToPoints(0.5)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = InchesToPoints(0.75)
        .TabPosition = wdUndefined
        .ResetOnHigher = 0
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = "Calibri"
        End With
        .LinkedStyle = ""
    End With
    ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
    Set CreateCustomListStyle = ListGalleries(wdBulletGallery).ListTemplates(1)
End Function

And finally, my test code to select all the paragraphs and make the list:

Option Explicit

Sub test()
    Dim oDoc As Document
    Set oDoc = ThisDocument

    oDoc.Range.Select       'selects all paragraphs
    Selection.Range.ListFormat.ApplyBulletDefault

    '--- create a list template that uses "-"
    Dim dashTemplate As ListTemplate
    Set dashTemplate = CreateCustomListStyle(oDoc)

    Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
        dashTemplate
End Sub

With the result:

enter image description here

Upvotes: 1

Sam
Sam

Reputation: 5721

When you got the ListGalleries.Item(3).ListTemplates(1).ListLevels(1).NumberFormat = ChrW(61485) as a result from your recording, you probably changed the style definition, but never applied it.

If you do the same recording again and examine it, you will hopefully find that it associated that to a style. A line that looks something like .LinkedStyle = "List Paragraph", but perhaps in German.

Work that part in to your existing macro and then, after selecting relevant parts of your document, do a

Selection.Style = ListGalleries.Item(3).ListTemplates(1).ListLevels(1).LinkedStyle

Upvotes: 1

Related Questions