Sub SaveWord(Item As Outlook.MailItem)
Dim oWord As Object
Dim sName As String
Dim dtDate As Date
sName = Item.Subject
dtDate = Item.ReceivedTime
sName = sName & dtDate
ReplaceCharsForFileName sName, "_"
Debug.Print sName
Set oWord = CreateObject("Word.Application")
With oWord
.Documents.Add
.Selection.InsertBefore (Item.Body)
.Visible = True
End With
Debug.Print "C:\Users\dianep\Documents\print\" & sName & ".docx"
oWord.activedocument.SaveAs2 FileName:="C:\Users\dianep\Documents\print\" & sName & ".docx", FileFormat:= _
wdFormatXMLDocument, CompatibilityMode:=15
Set oWord = Nothing
End Sub
Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "\", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
sName = Replace(sName, "&", sChr)
sName = Replace(sName, "%", sChr)
sName = Replace(sName, "*", sChr)
sName = Replace(sName, " ", sChr)
sName = Replace(sName, "{", sChr)
sName = Replace(sName, "[", sChr)
sName = Replace(sName, "]", sChr)
sName = Replace(sName, "}", sChr)
End Sub