Inserting text into incoming email Outlook 2013 lo

2019-02-28 09:54发布

I'm struggling to insert a string in an incoming email via VBA. The routine works fine when sending mail and it will work on incoming mail if the user clicks Actions Edit. The issue is that incoming mail is locked in read only mode. I've spent the past 13.5 hours searching everywhere. It is possible in earlier versions of Outlook, however Microsoft have removed the CommandBar functionality in Office 2013. Basically I need a way to allow the mail to be editable via a setting in VBA.

Here is the routine

Sub StampReference()
Dim objOL As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objDoc As Word.Document
Dim objSel As Word.Selection

strFullReference = "Reference: " & Reference
On Error Resume Next
Set objOL = Application
If objOL.ActiveInspector.EditorType = olEditorWord Then
    Set objDoc = objOL.ActiveInspector.WordEditor
    Set objNS = objOL.Session
    Set objSel = objDoc.Windows(1).Selection
    objSel.Move wdStory, -1
    objDoc.Characters(1).InsertBefore _
      strFullReference & vbCrLf & vbCrLf
    objSel.Move wdParagraph, 1
End If
Set objOL = Nothing
Set objNS = Nothing
End Sub

EDIT

I've cracked it! Here is the way to change the mode for anyone interested. It is quick and dirty, however it shows how it can be done. I took some code that someone had written to do a Resend and played around with variants to stumble across the correct value to edit. I call this routine just before stamping the information in

Sub SetEditMode()
Dim myItem As Outlook.MailItem
Dim objInsp As Outlook.Inspector
Dim objActionsMenu As Office.CommandBarControl
Dim olNewMailItem As Outlook.MailItem

On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
    Case "Explorer"
        Set myItem = ActiveExplorer.Selection.Item(1)
        myItem.Display
    Case "Inspector"
        Set myItem = ActiveInspector.CurrentItem
    Case Else
End Select
If myItem Is Nothing Then GoTo ExitProc
'edit mode
Set objInsp = ActiveInspector
objInsp.CommandBars.ExecuteMso ("EditMessage")
objActionsMenu.Execute

ExitProc:
End Sub

1条回答
Lonely孤独者°
2楼-- · 2019-02-28 10:25

I've cracked it! Here is the way to change the mode for anyone interested. It is quick and dirty, however it shows how it can be done. I took some code that someone had written to do a Resend and played around with variants to stumble across the correct value to edit. I call this routine just before stamping the information in

Sub SetEditMode()
Dim myItem As Outlook.MailItem
Dim objInsp As Outlook.Inspector
Dim objActionsMenu As Office.CommandBarControl
Dim olNewMailItem As Outlook.MailItem

On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
    Case "Explorer"
        Set myItem = ActiveExplorer.Selection.Item(1)
        myItem.Display
    Case "Inspector"
        Set myItem = ActiveInspector.CurrentItem
    Case Else
End Select
If myItem Is Nothing Then GoTo ExitProc
'edit mode
Set objInsp = ActiveInspector
objInsp.CommandBars.ExecuteMso ("EditMessage")
objActionsMenu.Execute

ExitProc:
End Sub

user2970334

查看更多
登录 后发表回答