如何格式化所选文字?

时间:2018-07-11 18:24:20

标签: outlook-vba outlook-2010

我正在尝试格式化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

1 个答案:

答案 0 :(得分:0)

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