vba - 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。
有人可以帮帮我吗?
解决方案
WdListType枚举( https://docs.microsoft.com/en-us/office/vba/api/word.wdlisttype ) 不包含wdNumberGallery
元素。您使用的整数值为wdNumberGallery
2,它等于wdListBullet
。因此,请尝试使用wdListSimpleNumbering
WdListType 枚举中的或其他值。此外,您的函数不返回值,因此您可以使用 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
推荐阅读
- java - 对象引用未保存的瞬态实例 - 在刷新休眠 JPA 之前保存瞬态实例
- deep-learning - 如何对抗机器学习数据集中的不平衡类
- r - 如何将物种箭头/向量添加到排序图中
- mysql - 查询使用没有强制索引的临时表
- batch-file - Bat文件从文本文件中删除数据
- sql - SYSTABLES 中每个表的行数
- java - 解析文档时如何用另一个字符串替换文档中字符串的一部分
- microsoft-graph-api - 将文件添加到团队或频道时,是否可以向团队成员发送电子邮件?
- apache-spark - 是否可以将 C* 一个表的数据从 spark 复制到另一个表而不将数据加载到 spark 内存中?
- rust - 如何为包含 Rc 的结构实现 Deref
>?