Change Outlook 2013 Email Theme Using VBA

I use the code below to save several selected letters in the standard file name format in a folder, which path is selected from the text box (textbox1). Depending on whether the checkbox1 checkbox is selected or not, it will be determined whether emails are deleted after the code is run. If the check box is not selected, emails are saved in the folder, but not deleted from Outlook. If this check box is not selected, I want the email subject in Outlook to be changed so that I know that I previously saved the email. In the code below, almost everything I want, except changing the email subject. If I select only one email address, everything will work fine. However, if I select more than one email, it changes only the subject of the first email. Any help was appreciated.

 Sub SaveIncoming()
 Dim lngC As Long
 Dim msgItem As Outlook.MailItem
 Dim strPath As String
 Dim FiledSubject As String

 On Error Resume Next
 strPath = UserForm1.TextBox1.Value
 On Error GoTo 0
 If strPath = "" Then Exit Sub
 If Right(strPath, 1) <> "\" Then strPath = strPath & "\"

 If TypeName(Application.ActiveWindow) = "Explorer" Then
 ' save selected messages in Explorer window
 If CBool(ActiveExplorer.Selection.Count) Then
 With ActiveExplorer
 For lngC = 1 To .Selection.Count
 If .Selection(lngC).Class = olMail Then
 MsgSaver3 strPath, .Selection(lngC)

 If UserForm1.CheckBox1.Value = True Then

  .Selection(lngC).Delete

  End If

  If UserForm1.CheckBox1.Value = False Then

 FiledSubject = "[Filed" & " " & Date & "]" & " " & .Selection(lngC).Subject

 .Selection(lngC).Subject = FiledSubject

 End If

 End If
 Next lngC
 End With
 End If
 ElseIf Inspectors.Count Then
 ' save active open message
 If ActiveInspector.CurrentItem.Class = olMail Then
 MsgSaver3 strPath, ActiveInspector.CurrentItem
 End If
 End If
 End Sub

Private Sub MsgSaver3(strPath As String, msgItem As Outlook.MailItem)
  Dim intC As Integer
  Dim intD As Integer
  Dim strMsgSubj As String
  Dim strMsgFrom As String
  strMsgSubj = msgItem.Subject
  strMsgFrom = msgItem.SenderName
  ' Clean out characters from Subject which are not permitted in a file name
  For intC = 1 To Len(strMsgSubj)
  If InStr(1, ":<>""", Mid(strMsgSubj, intC, 1)) > 0 Then
  Mid(strMsgSubj, intC, 1) = "-"
  End If
  Next intC
  For intC = 1 To Len(strMsgSubj)
  If InStr(1, "\/|*?", Mid(strMsgSubj, intC, 1)) > 0 Then
  Mid(strMsgSubj, intC, 1) = "_"
  End If
  Next intC

  ' Clean out characters from Sender Name which are not permitted in a           file      name
  For intD = 1 To Len(strMsgFrom)
  If InStr(1, ":<>""", Mid(strMsgFrom, intD, 1)) > 0 Then
  Mid(strMsgFrom, intD, 1) = "-"
  End If
  Next intD
  For intD = 1 To Len(strMsgFrom)
  If InStr(1, "\/|*?", Mid(strMsgFrom, intD, 1)) > 0 Then
  Mid(strMsgFrom, intD, 1) = "_"
  End If
  Next intD
  ' add date to file name
  strMsgSubj = Format(msgItem.SentOn, "yyyy-mm-dd Hh.Nn.Ss") & " "           & "[From " & strMsgFrom & "]" & " " & strMsgSubj & ".msg"
  msgItem.SaveAs strPath & strMsgSubj
  Set msgItem = Nothing
  UserForm1.Hide
  End Sub 
+4
1

, , 2 1. 2.

For lngC = 1 To .Selection.count

For lngC = .Selection.count to 1 step -1

For Each .

0

All Articles