I am looking to save the selected email to a specific directory, with the name of the email, and of course as a .msg file.This is what i have today, and it is not working. It saves a file but the name only has the first 2 characters (looks like it errors after the semi colon file name eg: FW or RE)... the content of the file is blank and the filetype has not been applied.'code to save selected emailDim selectedEmail As MailItemSet selectedEmail = ActiveExplorer.Selection.Item(1)Dim emailsub As Stringemailsub = ActiveExplorer.Selection.Item(1).Subject With selectedEmail .SaveAs "C:\direcotry\folder\" & emailsub & ".msg", olMSG End With谢谢你的期待.DOM推荐答案原因很简单.您的电子邮件主题包含无效字符.例如 : 这通常发生在电子邮件是 RE: 或 FWD:The reason is very simple. You email subject contains and Invalid Character. For example : This usually happens when the email is a RE: or FWD:试试这个Sub Sample() Dim selectedEmail As MailItem Dim emailsub As String Set selectedEmail = ActiveExplorer.Selection.Item(1) emailsub = GetValidName(selectedEmail.subject) 'Debug.Print emailsub With selectedEmail .SaveAs "C:\direcotry\folder\" & emailsub & ".msg", OlSaveAsType.olMSG End WithEnd SubFunction GetValidName(sSub As String) As String '~~> File Name cannot have these \ / : * ? " < > | Dim sTemp As String sTemp = sSub sTemp = Replace(sTemp, "\", "") sTemp = Replace(sTemp, "/", "") sTemp = Replace(sTemp, ":", "") sTemp = Replace(sTemp, "*", "") sTemp = Replace(sTemp, """", "") sTemp = Replace(sTemp, "<", "") sTemp = Replace(sTemp, ">", "") sTemp = Replace(sTemp, "|", "") GetValidName = sTempEnd Function 这篇关于以主题为文件名保存邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-22 03:33