Hi there!
I am having trouble with some code. I recently posted about a solution to saving out emails as text files, and was given a solution (thanks NipsMG!). I have since modified the code to then move the mail items to another folder once they had been saved out.
The whole process pretty much works ok, but I have a slight problem with the 'For i = 1 To myInbox.Items.Count' bit.
For me it seems to get stuck in a loop when i has a value of 10, so it then saves out the same email 10 times and doesnt actually move on to the next email.
Here is the code:
-------------------------------------------
Sub ExportMail()
Dim sFileName As String
On Local Error Resume Next
Dim oNS As NameSpace
Set oNS = ThisOutlookSession.GetNamespace("MAPI"
Dim MyMailbox As MAPIFolder
Dim myInbox As MAPIFolder
Dim i As Integer
Set MyMailbox = oNS.Folders.Item("Personal Folders" 'Very root name of your outlook folder dirs
Set myInbox = MyMailbox.Folders.Item("Bouncebacks" 'Where the mail is located
For i = 1 To myInbox.Items.Count
sFileName = "c:\Temp\MyMail\"
Set oItem = myInbox.Items.Item(i)
sFileName = sFileName & i & ".txt"
oItem.SaveAs sFileName, olTXT
DoEvents
'This folder needs to be within the folder where the mail is located
Set myDestFolder = myInbox.Folders("Done"
oItem.Move myDestFolder
sFileName = ""
DoEvents
Next i
End Sub
-------------------------------------------
I hope someone can help, or give me an idea of where I am going wrong.
Many thanks! - FateFirst
I am having trouble with some code. I recently posted about a solution to saving out emails as text files, and was given a solution (thanks NipsMG!). I have since modified the code to then move the mail items to another folder once they had been saved out.
The whole process pretty much works ok, but I have a slight problem with the 'For i = 1 To myInbox.Items.Count' bit.
For me it seems to get stuck in a loop when i has a value of 10, so it then saves out the same email 10 times and doesnt actually move on to the next email.
Here is the code:
-------------------------------------------
Sub ExportMail()
Dim sFileName As String
On Local Error Resume Next
Dim oNS As NameSpace
Set oNS = ThisOutlookSession.GetNamespace("MAPI"
Dim MyMailbox As MAPIFolder
Dim myInbox As MAPIFolder
Dim i As Integer
Set MyMailbox = oNS.Folders.Item("Personal Folders" 'Very root name of your outlook folder dirs
Set myInbox = MyMailbox.Folders.Item("Bouncebacks" 'Where the mail is located
For i = 1 To myInbox.Items.Count
sFileName = "c:\Temp\MyMail\"
Set oItem = myInbox.Items.Item(i)
sFileName = sFileName & i & ".txt"
oItem.SaveAs sFileName, olTXT
DoEvents
'This folder needs to be within the folder where the mail is located
Set myDestFolder = myInbox.Folders("Done"
oItem.Move myDestFolder
sFileName = ""
DoEvents
Next i
End Sub
-------------------------------------------
I hope someone can help, or give me an idea of where I am going wrong.
Many thanks! - FateFirst