我试图将附加到电子邮件的日常系统生成报告保存到文件夹。将Outlook附件保存到文件夹并用日期重命名该文件
然后,将附件文件名附加日期(文件中的修改日期)。我能够将文件保存到文件夹。但是,重命名的部分似乎不适合我。
有人可以帮助为什么重命名的一块不工作?非常感谢!
Public Sub saveAttachtoBIFolder(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim fso As Object
Dim oldName As Object
Dim file As String
Dim DateFormat As String
Dim newName As Object
saveFolder = "C:\BI Reports"
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
For Each objAtt In itm.Attachments
file = saveFolder & "\" & objAtt.DisplayName
objAtt.SaveAsFile file
Debug.Print "file="; file ' the full file path printed on immediate screen
Set oldName = fso.GetFile(file) ' issue seems to start from here
DateFormat = Format(oldName.DateLastModified, "yyyy-mm-dd ")
newName = DateFormat & objAtt.DisplayName
oldName.Name = newName
Debug.Print "DateFormat="; DateFormat 'the date format printed on the immediate screen
Set objAtt = Nothing
Next
Set fso = Nothing
End Sub
上的错误继续下一步应该只用于具有绕过错误的特定目的,然后使用On Error GoTo 0关闭。这里似乎没有用处。在错误恢复时删除以查看错误,以便您可以调试代码。 – niton