2016-08-24 20 views
1

電子メールメッセージのトピックを変更するボタン制御マクロを作成しようとしています。 this thread以下の私が管理している。この思い付いしますOutlook VBAで電子メールの件名を更新する

Public Sub Confidential() 

Dim Item As Outlook.MailItem 
Dim oInspector As Inspector 
Dim strSubject As String 

Set oInspector = Application.ActiveInspector 
If oInspector Is Nothing Then 
    Set Item = Application.ActiveExplorer.Selection.Item(1) 
Else 
    Set Item = oInspector.CurrentItem 
End If 

strSubject = Item.Subject 

' Remove previous Confidential and Legally Privileged 
strSubject = Replace(strSubject, "Confidential and Legally Privileged ", "") 

' Prefix subject with Confidential and Legally Privileged 
strSubject = "Confidential and Legally Privileged " & strSubject 

' Set the message subject 
Item.Subject = strSubject 


Set Item = Nothing 
Set oInspector = Nothing 


End Sub 

IF文は私の拠点をカバーしようとする試みである:ActiveInpectorが設定されているユーザーがポップアップウィンドウで電子メールを編集することができますいずれか、またはユーザーActiveExplorer.Selectionが設定されているときにreading paneで編集できます。

問題は、最初のケースではマクロが期待通りに機能しますが、2番目には(コードをデバッグしているときに変更が反映されていても)サブジェクトは変更されません。メッセージが選択されていても編集されていない場合(つまり、ユーザーが「返信」ボタンをクリックしていない)、メッセージリストのトピックをうまく変更しても効果があります。

今、私はthis threadですが、a)6歳以上であり、b)もう存在しないフォーラムを指しています。それに示唆されているように、私はItem.Saveメソッドを試しましたが、元の件名で編集したメッセージを閉じる以外は何もしないようです。

+0

エラーを投げますか? – 0m3r

+0

いいえ - 問題なく実行すると、 'item.subject'オブジェクトの変更intを見ることができますが、それは画面に表示されません。 – Yasskier

+1

変更の前または後に表示を呼び出しましたか?上記のコードでは表示されません。 –

答えて

1

@Ryan Wildryのおかげで答えた電子メールがエクスプローラペインで編集されている場合、ポップアップを強制し、それで動作するように.Displayメソッドを使用します。

Dim Item As Outlook.MailItem 
Dim oInspector As Inspector 
Set oInspector = Application.ActiveInspector 

If oInspector Is Nothing Then 
    Set Item = Application.ActiveExplorer.Selection.Item(1) 
    Item.Display 'Force the po-up 
    Set oInspector = Application.ActiveInspector 'Reassign oInpsector and Item again 
    Set Item = oInspector.CurrentItem 
Else 
    Set Item = oInspector.CurrentItem 
End If 
+0

ああ、あなたはそれを持っているクール、私は質問を理解して逃した。 ++ 1 – 0m3r

+0

一般に、 'Set Item = Nothing'の直前では、エクスプローラビューで更新するときに' Item.Save'が使用されます。ネイティブ機能では、手動で保存するように指示されるため、インスペクタビューでは不要です。 – niton

0

は、あなたがしようとしている何本です行う?

Option Explicit 
Public Sub Confidential() 
    Dim Item As Outlook.MailItem 
    Dim oInspector As Inspector 
    Dim strSubject As String 
    Dim strPrefixSubject As String 

    Set oInspector = Application.ActiveInspector 

    If oInspector Is Nothing Then 
     Set Item = Application.ActiveExplorer.Selection.Item(1) 
    Else 
     Set Item = oInspector.CurrentItem 
    End If 

    strSubject = "Confidential and Legally Privileged " 

    Debug.Print Item.Subject 

    ' Remove previous Confidential and Legally Privileged 
    Item.Subject = Replace(Item.Subject, strSubject, "", vbTextCompare) 
    Item.Save 

    ' Prefix subject with Confidential and Legally Privileged 
    strPrefixSubject = "Confidential and Legally Privileged " & Item.Subject 

    ' Set the message subject 
    Item.Subject = strPrefixSubject 
    Item.Save 


    Set Item = Nothing 
    Set oInspector = Nothing 

End Sub 
+0

これは実際には私が最初に問題を抱えていた場所です:このソリューションはウィンドウを閉じます(ユーザーは再度「返信」をクリックする必要があります)。メッセージリストの件名は更新されません。メッセージリストのボタンをクリックした後、「テスト」のままになりますが、実際には返信をクリックすると、変更された件名(https://s3.postimg.org/8d6wj7k7n/outlook)が表示されます。 PNG – Yasskier

関連する問題