从Outlook邮件项目中获取,发往,主题和日期

时间:2019-06-18 13:29:18

标签: vba outlook outlook-vba

我需要帮助来添加Date,From,To和Suject来构建pdf文件名。

'Construct a safe file name from the message subject
Dim msgFileName As String
msgFileName = MySelectedItem.Subject

Set oRegEx = CreateObject("vbscript.regexp")
oRegEx.Global = True
oRegEx.Pattern = "[\/:*?""<>|]"
msgFileName = Trim(oRegEx.Replace(msgFileName, ""))

我有此代码,但它仅将Subject保存为文件名。我尝试像这样构造,但不起作用:     msgFileName = MySelectedItem.Subject.From.To

1 个答案:

答案 0 :(得分:1)

这对于四个部分的串联应该足够了:

msgFileName = mySelectedItem.SentOn & mySelectedItem.Subject & mySelectedItem.SentOnBehalfOfName & mySelectedItem.To

要将行拆分为多行,使代码更具可读性,请使用-进行拆分:

msgFileName = mySelectedItem.SentOn & "-" & _
                mySelectedItem.Subject & "-" & _
                mySelectedItem.SentOnBehalfOfName & "-" & _
                mySelectedItem.To