2009-11-19 3 views
10

작업은 취소 기호을 선택한 텍스트 영역의 현재 글꼴에 적용하는 것입니다. 어려운 점은 Outlook에서 매크로 기록을 지원하지 않는다는 것입니다. 직접 작성해야하는 코드입니다.선택한 텍스트를 취소 할 MS Outlook 매크로

예를 들어, 다음과 같은 간단한 코드 : 여기

Run-time error '424': 
Object required 
+0

MS Outlook 2003을 사용하고 있습니다. 사전 정의 된 텍스트 블록 (예 : "문장이 굵게"또는 메시지 본문의 일부 패턴과 일치)이 아닌 수동으로 선택한 텍스트 (예 : 의미, 마우스 사용). – Andy

+0

님께 서 아래 질문에 대한 답변이 있는지 확인하고 싶습니다. –

답변

1

열려있는 메시지와 함께 장난에 대한 몇 가지주의 사항은 다음과 같습니다 Word 용

Selection.Font.Strikethrough = True 

작품,하지만 Outlook의 오류를 제공합니다 수표가 없다는 것은 열린 우편물이 있다고 가정합니다. 당신이하고 싶은 일과 어떤 버전에 대해 좀 더 이야기하고 싶다면 좀 더 도움을 줄 수있을 것입니다.

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 
+1

아이디어는 수동으로 선택한 텍스트 (예 : 마우스)에 글꼴을 적용하는 것입니다. 메시지 본문에는 선택에 대한 정보가 없습니다. – Andy

13

여기에는 사용자가 상자에 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 
+2

+1, Word가 없거나 Outlook이 HTML을 대신 사용하도록 설정된 경우에는 'ActiveInspector.HTMLEditor'를 통해 가져올 수 있습니다. – Aaronaught

1

Inspector의 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 
관련 문제