Saving And Deleting Outlook Attachments with Unknown Error Message

Status
Not open for further replies.

noobie

Member
Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server 2013
Hey Folks,

I am trying to write a macro that loops through an Outlook folder and its subfolders, looks for messages with attachments, saves them somewhere else (e.g. D:\...), and, if there has not been any error, deletes the specific attachment and writes down a log (I use that with in combination with a UserForm, and I also opt for restrictions on time and stuff).

Now I copied a huge folder into my personal account's test folder, and had the macro running. It worked fine, except for about 30 unknown errors in the log file (I use something like Resume Next if there occurs an error for a certain attachment).

I get an error that 'The requested operation could not be performed because of an unknown error.', with Microsoft Outlook as the Error Source, and with an error number like #-2147467259.

Now if I have the macro run all of the messages with this error (I copied the original messages into another test folder), they ARE processed, everything is just fine.

All of these messages do have some signature on them, so my first question is: does the signature yield such a problem?

I honestly doubt it, but just to be sure.

My second question is: does Outlook get some kind of error when you process large folders with a macro? I mean, I know about the Set/Nothing Error, but I also tried to be careful about this.

What is most surprising is that the log differs sometimes when you have the same procedure (several procedures are possible (offered by a UserForm)) running over the same folder again. Like copy messages into test folder, run the macro, look at the log. Reset everything, copy the messages again, run the macro => different log. Not totally different, but like 4 lines out of 1,500 lines.

The error seems to happen within this sub, so here it is (I am German, so I'll try to translate). I should not that all subs that are called within the specific sub do have their own error handlers.

Code:
Public Sub Move_With_DateRestriction(selFolder As Outlook.MAPIFolder, oMsg As Object, CurUser As Object, cdir As String, Prefix As String, tb1 As Double, tb2 As String, mv1 As Date, mv2 As Date)

Dim oMsgName As String, body As String, htmlbody As String, fs As Object, fso As Object, oMsgDate As String, oMsgDateDate As String, oMsgDateTime As String, selFolderPathName As String
Dim SaveString As String, NewSaveString As String, i As Long, StringToBeSaved As String

Set fs = CreateObject("Scripting.FileSystemObject")

For Each oMsg In selFolder.Items
      
         On Error GoTo Exception_And_Error_Handler:
      
         oMsgName = oMsg.Subject
         body = oMsg.body
         htmlbody = oMsg.htmlbody

      'make sure that the received time is in between the chosen dates (with MonthView1 and MonthView2)
 
            If oMsg.ReceivedTime >= mv1 And oMsg.ReceivedTime <= (mv2 + 1) Then
        
                selFolderPathName = Right(selFolder.FolderPath, Len(selFolder.FolderPath) - FindN("\", selFolder.FolderPath, 3))

                Set fs = CreateObject("Scripting.FileSystemObject")

                oMsgDateDate = Replace(Format(Left(oMsg.ReceivedTime, 10), "yyyy/mm/dd"), ".", "")
                oMsgDateTime = Right(Replace(oMsg.ReceivedTime, ":", "", 1), 6)
                oMsgDate = oMsgDateDate & "_" & oMsgDateTime
                SaveString = tb2 & "\" & selFolderPathName & "\" & Replacer(oMsgName) & "_" & oMsgDate
          
                If Not (fs.FolderExists(SaveString)) Then
 
                    Set fso = fs.CreateFolder(SaveString)
                    StringToBeSaved = SaveString
                    Call Store_Delete_and_Add(selFolder, oMsg, CurUser, cdir, Prefix, tb1, oMsgName, body, htmlbody, StringToBeSaved)
    
                Else
 
                    i = 1
 
                    NewSaveString = tb2 & "\" & selFolderPathName & "\Kopie_Nummer_" & i & "_" & Replacer(oMsgName) & "_" & oMsgDate
        
                    Do While fs.FolderExists(NewSaveString) = True
    
                        i = i + 1
                        NewSaveString = tb2 & "\" & selFolderPathName & "\Kopie_Nummer_" & i & "_" & Replacer(oMsgName) & "_" & oMsgDate
        
                    Loop
        
                    Set fso = fs.CreateFolder(NewSaveString)
                    StringToBeSaved = NewSaveString
                    Call Store_Delete_and_Add(selFolder, oMsg, CurUser, cdir, Prefix, tb1, oMsgName, body, htmlbody, StringToBeSaved)
 
                End If
          
            End If
        
         GoTo Skip:
          
Exception_And_Error_Handler:
      
    Select Case Err.Description
      
         'Fehler #1:
         Case "Objekt unterstützt diese Eigenschaft oder Methode nicht."
            Set fso = fs.OpenTextFile(cdir & "Logs\log_new_" & CurUser & ".txt", 8, 2)
            fso.WriteLine
            fso.Write " Die Nachricht '" & oMsgName & "' wurde nicht weiter bearbeitet. Grund: Der HTML-Body der Nachricht konnte nicht entschlüsselt werden."

            'The message '" & oMsgName & "' was not processed any further. Reason: The HTML-Body could not be deciphered."

            fso.Close
      
         'Fehler #2:
         Case "Pfad nicht gefunden"
            Set fso = fs.OpenTextFile(cdir & "Logs\log_new_" & CurUser & ".txt", 8, 2)
            fso.WriteLine
            fso.Write "  Die Nachricht '" & oMsgName & "' wurde nicht weiter bearbeitet. Grund: Nicht behandelbare Ausnahme. Speicherpfad zu lang. Bitte manuell überprüfen!"

           'The message '" & oMsgName & "' was not processed any further. Reason: Exception that cannot be handled. Save Path is too long."

            fso.Close
      
         'Fehler #infinity:
         Case Else
            Set fso = fs.OpenTextFile(cdir & "Logs\log_new_" & CurUser & ".txt", 8, 2)
            fso.WriteLine
            fso.Write " Die Nachricht '" & oMsgName & "' wurde nicht weiter bearbeitet. Grund: nicht behandelbare Ausnahme."

'The message '" & oMsgName & "' was not processed any further. Reason: Exception that cannot be handled."

            fso.WriteLine
            fso.Write "  (#" & Err.Number & "), (Description: " & Err.Description & "), (Source: " & Err.source & ")."
            fso.Close
      
    End Select
      
         Resume Skip:
      
Skip:
        
Next

Set fso = Nothing
Set fs = Nothing

End Sub

Thanks in advance for any help :)
 
So, now I tested the macro on another folder that I copied and I worked like a charm. 3,600 messages and only 2 error lines in the log, both of which I expected (file name too Long).

So I come to the conclusion that there must indeed be a conflict with the digital signatures of the messages within the previous folder.

Is there any PidTag that I could search for with the Property Accessor?
image8.png
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Rupert Dragwater Background colors not saving in Outlook 365 Using Outlook 15
R Saving Emails and Attachments as .msg file Using Outlook 3
CWM550 Saving Data: Don't check certain folders Using Outlook 2
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
D Outlook 2016 Outlook not saving Sent Items Using Outlook 4
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
M Adding Subject to this Link-Saving VBA Outlook VBA and Custom Forms 5
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
D Saving Selected Emails as PDF and saving Attachments Outlook VBA and Custom Forms 6
B Saving items under a folder Using Outlook 3
R Quick Access view in File Explorer when saving attachments Using Outlook 0
V Saving attachment from outlook in My Documents Outlook VBA and Custom Forms 14
M Dialog called up multiple times when saving emails from macro Outlook VBA and Custom Forms 2
A saving attachement to folder named the same as rule name Outlook VBA and Custom Forms 0
T Saving all email to file folder in Windows Using Outlook 2
J Saving attachments from specific sender (phone number) to specific folder on hard drive Using Outlook 3
C Saving Outlook attachments and links to attachments with VBA Outlook VBA and Custom Forms 2
Kevin H Remotely saving emails Using Outlook 1
R Outlook 2010 Modify Style "Do not check spelling or grammar" not saving Outlook VBA and Custom Forms 0
R Outlook Office 365 not saving addresses Using Outlook 0
A Keep color categories when saving vCards Using Outlook 1
P Saving All Messages to the Hard Drive Using VBA Outlook VBA and Custom Forms 5
e_a_g_l_e_p_i question about saving my .pst so I can import it to my Outlook after I build a new system Using Outlook 10
S Editing an email with notes and saving it for record using Macro Outlook VBA and Custom Forms 3
O Saving Attachments to folder on disk and adding Initials to end of file name Outlook VBA and Custom Forms 9
J Outlook 2013 crashes saving VBA & clicking tools | digital signature Outlook VBA and Custom Forms 1
bifjamod Saving sent email to specific folder based on category with wildcard Outlook VBA and Custom Forms 1
N Saving .msg as sent item on send Outlook VBA and Custom Forms 1
erichamion Changes to meeting body not properly saving Outlook VBA and Custom Forms 4
A ItemAdd on Imap Folder get endless loop after saving item Using Outlook 5
T Saving Outlook 2010 email with attachments but read the email without Outlook Using Outlook 2
T From Field Blank when saving to folder other than Sent items Using Outlook 2
L Outlook DST (Daylight Saving Time) problem Using Outlook 0
F Using Outlook 2007 as an IMAP Mail Station Without Saving Data Locally Using Outlook 2
E Saving Changes To Edited E-Mail Received Message Using Outlook 0
D File Lock issue when saving message from Outlook to new folder Using Outlook 1
D Remove extension while saving attachments Using Outlook 1
K Printing & Saving Outlook Contacts Using Outlook 3
S Not saving attachments in the Sent Folder Using Outlook 2
S trouble with Outlook 2010 saving sent emails Using Outlook 2
D Saving outlook emails in html and attachments Using Outlook 4
W Default Saving a message as text Using Outlook 2
R Outlook 2007 QAT buttons not saving Using Outlook 2
C Exchange 2003 - Outlook 2003 - Calendar entries saving over each other Using Outlook 2
J Saving Published Outlook Form as msg Using Outlook 1
J Saving recent colors used for fonts in an email? Using Outlook 1
B How to choose which contacts folder to use when saving contacts? Using Outlook 1
J Saving Incoming & Outgoing Outlook 2010 Email Locally with IMAP Using Outlook 2
F Saving Imap Drafts Using Outlook 1

Similar threads

Back
Top