【问题标题】:How to format selected text?如何格式化选定的文本?
【发布时间】:2018-12-19 21:09:46
【问题描述】:

我正在尝试在 Outlook 2010 中格式化所选文本。

我录制了一个适用于 Word 的宏。

在我到达工作 Word 代码之前,我的 Outlook 代码在第二行失败。

我多年来一直使用 VBA,几乎完全使用 Excel。

Option Explicit
Public Sub UseWord_Fmt()
'   Wrapper
    Dim Ins As Outlook.Inspector
    Dim wDoc As Word.Document
    Dim Word As Word.Application
    Dim Selection As Word.Selection

    Set Ins = Application.ActiveInspector
    Set wDoc = Ins.WordEditor
    Set Word = wDoc.Application
    Set Selection = Word.Selection
'
'
    ' My code, generic so that I can later modify
'
'
    Selection.HomeKey Unit:=wdStory
    Selection.MoveDown Unit:=wdLine, Count:=4, Extend:=wdExtend
    With Selection.ParagraphFormat
        .LeftIndent = InchesToPoints(0)
        .RightIndent = InchesToPoints(0)
        .SpaceBefore = 6
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = InchesToPoints(0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With

End Sub

【问题讨论】:

  • 错误是什么?确定具体的代码行。
  • 设置对 Microsoft Word 对象模型的引用。

标签: vba outlook outlook-2010


【解决方案1】:

Outlook 不理解 InchesToPoints(0) 将测量值从英寸转换为点时 - 只需使用 .LeftIndent = (0),或指定 Application 示例 Word.InchesToPoints(0)强>


Public Sub UseWord_Fmt()
'   Wrapper
    Dim Ins As Outlook.Inspector
    Dim wDoc As Word.Document
    Dim Word As Word.Application
    Dim Selection As Word.Selection

    Set Ins = Application.ActiveInspector
    Set wDoc = Ins.WordEditor
    Set Word = wDoc.Application
    Set Selection = Word.Selection
'
'
    ' My code, generic so that I can later modify
'
'
    Selection.HomeKey Unit:=wdStory
    Selection.MoveDown Unit:=wdLine, Count:=4, Extend:=wdExtend
    With Selection.ParagraphFormat
        .LeftIndent = (0)
        .RightIndent = (0)
        .SpaceBefore = 6
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphLeft
        .WidowControl = True
        .KeepWithNext = False
        .KeepTogether = False
        .pageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = (0)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
    End With
End Sub

【讨论】:

    猜你喜欢
    • 2011-01-08
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多