首页 > 解决方案 > VBA wdNumberGallery 设置项目符号而不是数字

问题描述

我有以下功能,我想将特定样式应用于我的 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。

有人可以帮帮我吗?

标签: vbams-word

解决方案


WdListType枚举( https://docs.microsoft.com/en-us/office/vba/api/word.wdlisttype ) 不包含wdNumberGallery元素。您使用的整数值为wdNumberGallery2,它等于wdListBullet。因此,请尝试使用wdListSimpleNumberingWdListType 枚举中的或其他值。此外,您的函数不返回值,因此您可以使用 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

推荐阅读