Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Outlook macro to strikeout selected text

The task is to apply strikeout to current font in selected text area. The difficulty is that Outlook doesn't support recording macros on the fly - it wants code to be written by hand.

For example, the following simple code:

Selection.Font.Strikethrough = True

works for Word, but gives an error for Outlook:

Run-time error '424':
Object required
like image 962
Andy Avatar asked Nov 19 '09 13:11

Andy


2 Answers

This assumes that you also have Word installed on your box. If so, you can access most of the Word OM from the Outlook VBE without referencing Word by using the ActiveInspector.WordEditor object.

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
like image 88
Todd Main Avatar answered Oct 20 '22 18:10

Todd Main


Here are a few notes on messing around with the open message, there are no checks, it just assumes that you have an open mail item. If you would like to say a little more about what you want to do, and in what version, I may be able to help a little more.

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
like image 31
Fionnuala Avatar answered Oct 20 '22 19:10

Fionnuala