首页 > 解决方案 > 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整个单元格时,会向左移动,而不仅仅是列表。

这是我正在寻找的结构
图片:这是我正在寻找的结构

标签: vbaoutlookms-word

解决方案


不确定在 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,这并不明显)。


推荐阅读