klornpallier
Technical User
I have code that forwards a mail based on an Outlook item subject name in the Subfolder "Percentage Reports" and then moves the item to another directory "Migration Reports".
This works fine as long as I have an item in the "Percentage Reports" subfolder. If I dont when a new mail arrives I get and error "Array Index out of Bounds error". This is use with the rules wizard to move the Item to the "Percentage Reports" folder, My code is:
Private Sub Application_NewMail()
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set SubFolderA = myfolder.Folders("Percentage Reports")
Set myforward = SubFolderA.Items(1).Forward
Set SubFolder = myfolder.Folders("Migration Reports")
Dim emailname$
For Each Item In SubFolderA.Items
MsgBox Left(Item.Subject, 3)
If Left(Item.Subject, 3) = "Loa" Then 'PERCENTAGE REPORTS
Open "C:\emailnamesWave 1.txt" For Input As #1
Do Until EOF(1)
Line Input #1, emailname
myforward.Recipients.Add emailname
Loop
Close #1
myforward.Send
Item.Move (SubFolder)
End If
End Sub
This works fine as long as I have an item in the "Percentage Reports" subfolder. If I dont when a new mail arrives I get and error "Array Index out of Bounds error". This is use with the rules wizard to move the Item to the "Percentage Reports" folder, My code is:
Private Sub Application_NewMail()
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set SubFolderA = myfolder.Folders("Percentage Reports")
Set myforward = SubFolderA.Items(1).Forward
Set SubFolder = myfolder.Folders("Migration Reports")
Dim emailname$
For Each Item In SubFolderA.Items
MsgBox Left(Item.Subject, 3)
If Left(Item.Subject, 3) = "Loa" Then 'PERCENTAGE REPORTS
Open "C:\emailnamesWave 1.txt" For Input As #1
Do Until EOF(1)
Line Input #1, emailname
myforward.Recipients.Add emailname
Loop
Close #1
myforward.Send
Item.Move (SubFolder)
End If
End Sub