タスクは、選択したテキスト領域の現在のフォントに取り消し線を適用することです。問題は、Outlook がその場でのマクロの記録をサポートしていないことです。コードを手動で記述する必要があります。
たとえば、次の単純なコード:
Selection.Font.Strikethrough = True
Word では機能しますが、Outlook ではエラーが発生します。
Run-time error '424':
Object required
タスクは、選択したテキスト領域の現在のフォントに取り消し線を適用することです。問題は、Outlook がその場でのマクロの記録をサポートしていないことです。コードを手動で記述する必要があります。
たとえば、次の単純なコード:
Selection.Font.Strikethrough = True
Word では機能しますが、Outlook ではエラーが発生します。
Run-time error '424':
Object required
これは、ボックスに Word もインストールされていることを前提としています。その場合、 ActiveInspector.WordEditorオブジェクトを使用して、Word を参照せずに Outlook VBE から Word OM のほとんどにアクセスできます。
Sub StrikeThroughinMailItem()
Dim objOL As Application
Dim objDoc As Object
Dim objSel As Object
Set objOL = Application
Set objDoc = objOL.ActiveInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Font.Strikethrough = True
End Sub
開いているメッセージをいじり回すことに関するいくつかの注意事項があります。チェックはありません。開いているメールアイテムがあることを前提としています。あなたがやりたいこと、そしてどのバージョンで、私がもう少し助けることができるかもしれないことについてもう少し言いたいなら。
Dim ActiveMessage As MailItem
Dim strHTML As String
Set ActiveMessage = ActiveInspector.CurrentItem
Debug.Print ActiveMessage.Body
Debug.Print ActiveMessage.HTMLBody
strHTML = Replace(ActiveMessage.Body, "This sentence is bold", _
"<STRONG>This sentence is bold</STRONG>")
ActiveMessage.HTMLBody = strHTML
Debug.Print ActiveMessage.HTMLBody
インスペクターの HTMLEditor または WordEditor にアクセスする必要があります。サンプル コードについては、ヘルプ ファイルを確認してください。WordEditor を使用している場合は、Word でマクロを記録し、WordEditor を使用して結果のコードを Outlook マクロに組み込むことができます。
Public Sub DoIt()
'must set word as mail editor
'must set reference to word object library
Dim oInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oItem As Outlook.MailItem
Set oItem = Outlook.Application.CreateItem(olMailItem)
oItem.BodyFormat = olFormatRichText 'must set, unless default is rich text
Set oInspector = oItem.GetInspector
oInspector.Display 'must display in order for selection to work
Set oDoc = oInspector.WordEditor
'better to use word document instead of selection
'this sample uses selection because word's macro recording using the selection object
Dim oSelection As Word.Selection
Set oSelection = oDoc.Application.Selection
oSelection.TypeText Text:="The task is to apply strikethroughout."
oSelection.MoveLeft Unit:=wdCharacter, Count:=4
oSelection.MoveLeft Unit:=wdCharacter, Count:=7, Extend:=wdExtend
oSelection.Font.Strikethrough = True
End Sub