I'm trying to create a command that sends a collection of emails to their corresponding folders within Outlook.
The 'Search_Test_String' is correctly found (as per the previous message boxes) but I receive an "Array index out of bounds." error on "Selected_Emails.Item(a_index).Move(main_folder)" or "Selected_Emails.Item(a_index).Move(first_subfolder)". If possible, please advise how to fix this issue.
Code: Select all
Outlook_App := ComObjActive("Outlook.Application")
Selected_Emails := Outlook_App.ActiveExplorer.Selection
Loop, % Selected_Emails.count
{
Search_Test_String := "720292"
for main_folder in Outlook_App.GetNamespace("MAPI").GetDefaultFolder(6).Folders
{
if InStr(main_folder.name, Search_Test_String)
{
MsgBox, % main_folder.name
Selected_Emails.Item(a_index).Move(main_folder)
break
}
for first_subfolder in main_folder.Folders
{
if InStr(first_subfolder.name, Search_Test_String)
{
MsgBox, % first_subfolder.name
Selected_Emails.Item(a_index).Move(first_subfolder)
break 2
}
}
}
}
return
https://stackoverflow.com/questions/48505811/array-index-out-of-bounds-vba-outlook
Thank you sincerely for any assistance you are able to provide!