我試圖將附加到電子郵件的日常系統生成報告保存到文件夾。將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