Results 1 to 10 of 10

Thread: Export Macro Stops due to File Path being too Long

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Export Macro Stops due to File Path being too Long

    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:

            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
    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?

    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:

        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
    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!

    Thanks!
    Last edited by Bob Phillips; 12-19-2019 at 07:51 AM. Reason: Added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •