Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 在Outlook WordEditor中缩进表中项目符号列表的列表项_Vba_Outlook_Ms Word - Fatal编程技术网

Vba 在Outlook WordEditor中缩进表中项目符号列表的列表项

Vba 在Outlook WordEditor中缩进表中项目符号列表的列表项,vba,outlook,ms-word,Vba,Outlook,Ms Word,我正试图用Outlook VBA和Excel工作表中的数据撰写一封电子邮件 我将Excel中的一个表格粘贴到邮件中,现在想将一些单元格格式化为表格中的项目符号列表 现在我需要格式化单元格的文本,例如,作为项目符号列表 这适用于以下代码: Dim currentCell As Variant currentCell = wdDoc.Tables(1).Cell(2, 2) currentCell.ListFormat.ApplyBulletDefault 如何将单元格(2,2)中的文本格式化为具

我正试图用Outlook VBA和Excel工作表中的数据撰写一封电子邮件

我将Excel中的一个表格粘贴到邮件中,现在想将一些单元格格式化为表格中的项目符号列表

现在我需要格式化单元格的文本,例如,作为项目符号列表

这适用于以下代码:

Dim currentCell As Variant
currentCell = wdDoc.Tables(1).Cell(2, 2)
currentCell.ListFormat.ApplyBulletDefault
如何将单元格(2,2)中的文本格式化为具有多个缩进的项目符号列表

当我使用
currentCell.ListFormat.ListIndent
时,整个单元格会向左移动,而不仅仅是列表

这就是我正在寻找的结构

此VBA函数创建邮件并在邮件正文中添加项目符号列表。 现在您只需要用单元格中的数据替换
text
变量

Sub send()

    Dim objOutlook As Object
    Dim objMail As Object
    Dim text As String

    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)

    text = "This is a summary" & Chr(10) & _
    Chr(149) & " First point" & Chr(10) & _
    Chr(149) & " Second point" & Chr(10) & _
    Chr(149) & " Last point"

    With objMail
       .To = "name@domain.de"
       .Subject = "Subject"
       .Body = text
       .Display
    End With

End Sub
如果要将项目符号列表添加到一个单元格中,可以使用相同的方法,例如,以下代码将列表添加到当前活动单元格中:

Sub Bullets()
    Text = "This is a summary" & Chr(10) & _
        Chr(149) & " First point" & Chr(10) & _
        Chr(149) & " Second point" & Chr(10) & _
        Chr(149) & " Last point"

    ActiveCell.Value = Text
End Sub

不确定在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
Const bulletLTName As String=“mybullet”
使用ActiveDocument
'除非您总是创建新文档,否则您可能会
'需要验证mybullet不存在并删除,然后重新创建,
”“或者修改。这里没有。
With.ListTemplates.Add(大纲编号:=False,名称:=BulletLTName)
带.ListLevels(1)
.NumberFormat=“-
'如果需要修改项目符号字体,您可以这样做
“像这样。。。
使用.Font
.Name=“”
.尺寸=10英尺等。
以
'您可以修改其他布局属性-最好
'查看Word的对象模型,但例如
.NumberPosition=0
.TabPosition=10
.TextPosition=10’,依此类推。
以
以
带.Tables(1).单元格(2,2).范围
.Text=“Text”
.ListFormat.ApplyListTemplate.Document.ListTemplates(bulletLTName)
以
以

虽然currentCell确实起作用,但我会尽量避免将其定义为变体,因为这会使代码不那么明显(例如,正如所写,currentCell是一个单词范围而不是一个单词单元格,这并不明显)。

感谢您的回答,但我想在电子邮件中保留excel表。我编辑了我的问题以便澄清。很抱歉造成混淆。我想保留表格单元格中已经存在的文本,并将其格式化为项目符号列表。此解决方案将替换数据。我想它是用
ListFormat.ApplyListTemplate
完成的,但我不知道怎么做?我在这里想的是使用
Chr(149)
作为项目符号。当然,您需要将
文本
变量替换为单元格中已经存在的数据,并将其与
Chr(149)
组合。我理解您的观点,但这仍然不是我想要的结果,因为内容是多行的,没有像项目符号列表那样正确缩进。我附上了一张图片的结构,我想我的问题。谢谢你这有帮助!还有一个问题。当我执行
currentCell.ListFormat.listdindent时,表的整个单元格缩进,而不仅仅是单元格中的列表。然后打破了桌子。如何解决这个问题?我想增加右边的选项卡(缩进ListLevel)。因此,我尝试使用.ListLevel(1).NumberFormat=“-”.TabPosition=50.NumberPosition=20以“``结尾,但两者都没有任何效果。我做错了什么?