vba - Outlook WordEditor 表格中项目符号列表的缩进列表项
问题描述
我正在尝试使用 Excel 工作表中的数据使用 Outlook VBA 撰写电子邮件。
我将 Excel 中的表格粘贴到邮件中,现在想将一些单元格格式化为表格内的项目符号列表。
现在我需要将单元格的文本格式化为项目符号列表。
这适用于以下代码:
Dim currentCell As Variant
currentCell = wdDoc.Tables(1).Cell(2, 2)
currentCell.ListFormat.ApplyBulletDefault
如何将 Cell(2,2) 中的文本格式化为具有多个缩进的项目符号列表?
当我使用currentCell.ListFormat.ListIndent
整个单元格时,会向左移动,而不仅仅是列表。
解决方案
不确定在 Outlook 中这是如何工作的,但在 Word 中,您需要创建一个具有相关项目符号样式布局的 ListTemplate,然后应用它。像这样的东西:
Const bulletLTName As String = "mybullet"
With ActiveDocument
' Unless you are always creating new documents, you might
' need to verify that mybullet doesn't exist and delete then recreate,
' or modify. Not done here.
With .ListTemplates.Add(OutlineNumbered:=False, Name:=BulletLTName)
With .ListLevels(1)
.NumberFormat = "-"
' If you need to modify the bullet font, you can do it
' like this...
With .Font
.Name = "<whatever font name you want to use>"
.Size = 10 ' etc.
End With
' You can modify other layout properties - best to
' look at Word's object model, but for example
.NumberPosition = 0
.TabPosition = 10
.TextPosition = 10 ' and so on.
End With
End With
With .Tables(1).Cell(2, 2).Range
.Text = "text"
.ListFormat.ApplyListTemplate .Document.ListTemplates(bulletLTName)
End With
End With
虽然它确实起作用,但我会尽量避免将 currentCell 定义为 Variant,因为它会使代码不那么明显(例如,正如所写的那样,currentCell 是一个 Word Range 而不是 Word Cell,这并不明显)。
推荐阅读
- javascript - 具有渐变背景的动画计数
- python - 如何正确地将对向量进行操作的函数推广到对多维数组进行操作的函数?
- reactjs - 当我使用 Link 或 NavLink 导航到 React 组件时,我的 Materialize css sidenav 汉堡菜单不起作用
- c# - AutoMapper - 当源属性不可用时将目标属性设置为 null
- angular - 角度日期时间选择器ngModel不起作用
- java - java中匿名类的范围
- asp.net-core - 如何安装更新的 MSBuild 版本?
- java - cobertura 不会读取所有测试用例
- entity-framework - 缺少 EF Core DbPropertyValues。有替代方案吗?
- sticky-session - 在 Azure Web App for Linux 容器中维护粘性会话