I am trying to create a macro in Outlook to open a selected message in the inbox, append a string of text to the subject, then save, and close the open message.
This is what I have so far, the only step in the process that I still need is the ability to open the message when the macro is started. I can add the text to the subject, save, and close.
Any help would be great.
This is what I have so far, the only step in the process that I still need is the ability to open the message when the macro is started. I can add the text to the subject, save, and close.
Code:
Option Explicit
Public Sub Application_InitialDH()
On Error Resume Next
Dim MsgColl As Object
Dim msg As Outlook.MailItem
Dim objNS As Outlook.NameSpace
Dim i As Long
Dim subjectname As String
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
' a collection of selected items
Set MsgColl = ActiveExplorer.Selection
subjectname = MsgColl.Subject & " ~DH"
Case "Inspector"
' only one item was selected
Set msg = ActiveInspector.CurrentItem
subjectname = msg.Subject & " ~DH"
End Select
On Error GoTo 0
If (MsgColl Is Nothing) And (msg Is Nothing) Then
GoTo ExitProc
End If
If Not MsgColl Is Nothing Then
For i = 1 To MsgColl.Count
' set an obj reference to each mail item so we can move it
Set msg = MsgColl.Item(i)
With msg
.Subject = subjectname
.Close (olSave)
End With
Next i
ElseIf Not msg Is Nothing Then
msg.Subject = subjectname
msg.Close (olSave)
End If
ExitProc:
Set msg = Nothing
Set MsgColl = Nothing
Set objNS = Nothing
End Sub
Any help would be great.