VBA Number Gallery 设置项目符号而不是数字

VBA wdNumberGallery set bulletpoints and not numbers

我有以下功能,我想将特定样式应用于我的 word 文档中的所有编号元素:

Function SetNumberingStyle()
Dim para As Paragraph, i As Long
  For Each para In ActiveDocument.Paragraphs
    i = i + 1
    If para.Range.ListFormat.ListType = wdNumberGallery Then
        para.Style = ("List Number")
    End If
  Next para
End Function

问题是这个函数将所有特定样式设置为我单词中的所有要点,但我不知道为什么? 我知道对于要点,有 ListType wdListBullet。

有人可以帮我吗?

WdListType 枚举 (https://docs.microsoft.com/en-us/office/vba/api/word.wdlisttype) 不包含 wdNumberGallery 元素。您使用的整数值 wdNumberGallery 是 2,等于 wdListBullet。因此,请尝试使用 wdListSimpleNumbering 或 WdListType 枚举中的其他值。此外,您的函数没有 return 值,因此您可以使用 Sub 而不是 Function:

Sub SetNumberingStyle()
    Dim para As Paragraph
    For Each para In ActiveDocument.Paragraphs
        If para.Range.ListFormat.ListType = wdListSimpleNumbering Then
            para.Style = "List Number"
        End If
    Next para
End Sub