我正在Outlook 2010中创建一个将电子邮件保存到指定文件夹的宏。电子邮件将保存到由宏创建的文件夹中。我在考虑的问题是我在周末或非工作时间收到电子邮件的时间。我注意到的是,当我周末收到电子邮件并在周一重新打开Outlook时,宏运行正常并做了它需要做的事情,但是周末收到的电子邮件会被放入星期一文件夹中。我该如何绕过这个问题。如果我在星期六收到一封电子邮件,我怎么能拥有这个宏,以便它也会为星期六创建一个文件夹?这是我目前正在处理的代码。
Public Sub SaveMsgs(Item As Outlook.MailItem)
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim enviro As String
Dim sSender As String
Dim strFolder As String
Dim strNewFolder As String
Dim save_to_folder As String
enviro = CStr(Environ("USERPROFILE"))
sName = Item.Subject
ReplaceCharsForFileName sName, "_"
sSender = Item.Sender
dtDate = Item.ReceivedTime
sName = sSender & " - " & sName & ".msg"
strNewFolder = Format(Date, "mm-dd-yyyy")
strFolder = "C:\IT Documents\" & strNewFolder & "\"
If Len(Dir(strFolder, vbDirectory)) = 0 Then
MkDir (strFolder)
End If
save_to_folder = strFolder
Item.SaveAs save_to_folder & sName, olMSG
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)
End Sub
答案 0 :(得分:0)
好像您打算使用Item.ReceivedTime
来创建文件夹,但在将此值提取到dtDate
后,它永远不会被使用。
也许请尝试以下方法:
strNewFolder = Format(dtDate, "mm-dd-yyyy")
^^