【发布时间】: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