Hi all,
I have a macro that exports emails in a specific folder. The macro takes the subject line, adds a date and time stamp and then exports it. This has worked great thus far. Recently it started to error out and I have figured out the cause to be when the subject line is a bit longer, coupled with the file path length it errors out.
Here is my code:
The problem email will not export. If I Shorten the file path to just "G:\Special" it works fine. I tried to google a solution but came up empty. I am wondering if anyone has any ideas?If TypeName(aItem) = "MailItem" Then path = "G:\Special\This_is_a_test_folder123\123\General Communication" & aItem.Subject & " " & mattcombine & zachcombine & ".msg" aItem.SaveAs (path) 'Debug.Print Item.ConversationTopic End If Next
Also I tried On Error Resume Next but the only issue I have is after the export, I then run the below code which deletes all of the emails:
If I use "On Error Resume Next" the vba code will skip exporting the email with the issue but then the delete code will delete it. If someone knows a way to merge the export and delete code so that "On Error Resume Next" does not export or delete the problem email, that would be a good solution too!total_messages = objFolder.Items.Count For i = 1 To total_messages message_index = total_messages - i + 1 Set oMessage = objFolder.Items.Item(message_index) oMessage.Delete Set oMessage = Nothing Next
Thanks!





Reply With Quote