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.
Thanks in advance for any help
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