|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am a newbie struggling with the following code to run in MS Outlook. The purpose is to check all mail in my inbox and to separate it into folders using different strings in the subject line. The first step is to separate out all those commencing Read: or Delivered: etc. These are to be put in the AutoDel folder which I have created in Mailbox - JSP. Subsequent versions will use project numbers to segregate.
At the moment I get runtime error '-2147352567 (80020009)' Array index out of bounds. Line highlighted below Can anyone see my error - it must be something fairly simple for experienced hackers but way beyond me. I look forward to hearing from you. Many thanks ScriptHam PS: very sorry - indenting not working Code:
Sub AutoDel_1() '************************************************* ********* ' Project to segregate/delete emails where subject line ' commences as per strSearch below e.g. Read: ... ' ' REFERENCES: ' Absolute Beginners Guide to VBA, QUE, PaulMcFedries ' http://www.mcfedries.com/abgvba/Chapter11.txt '_________________________________________________ _________ 'DECLARATIONS 'VARIABLES Dim ns As NameSpace Dim ib As MAPIFolder Dim msg As MailItem ' Dim fldr As MAPIFolder experimented with - nogo Dim strSearch1 As String Dim strSearch2 As String Dim strSearch3 As String ' Dim strsubject As String experimented with - nogo 'ASSIGN OBJECTS TO VARS. Set ns = ThisOutlookSession.Session Set ib = ns.GetDefaultFolder(olFolderInbox) 'Set fldr = ns.GetFolderFromID(AutoDel) 'INITIALISE VARS. strSearch1 = Read: strSearch2 = Delivered: strSearch3 = "Delivery Status Notification (Relay)" 'CODE For Each msg In ib.Items 'find opening words in the subject line and test = Read: or = Delivered: etc. 'if first appearance of str Read etc. is at position 1 then Move to AutoDel folder which exists 'Set strSubject = MailItem.subject experimented with - nogo If InStr(1, msg.subject, strSearch1, 1) = 1 Then 'first position in subject line, textual search msg.Move ns.Folders(1).Folders(AutoDel) runtime error '-2147352567 (80020009)' Array index out of bounds ElseIf InStr(1, msg.subject, strSearch2, 1) = 1 Then MailItem.Move (AutoDel) ElseIf InStr(1, msg.subject, strSearch3, 1) = 1 Then MailItem.Move (AutoDel) End If Next |
|
#2
|
|||
|
|||
|
My guess is ns.Folders(1) isn't a valid array node.
Just guessing, can't you step through your code with the debugger to pin down the problem?
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
|||
|
|||
|
Thanks DougG.
I am struggling with the idea of an array node let alone how it relates to objects in Outlook VBA. Technically you are very probably correct. Presumably an array node is the memory location for array element zero. Stepping through using the debug doesn't reveal much I regret. It is only fair to tell you that I have put the same post on http://www.theofficeexperts.com/for...read.php?t=4274 where I have had a different response but not much immediate progress. I look forward to hearing any more ideas. Many thanks ScriptHam. |
|
#4
|
|||
|
|||
|
Some more progress here http://www.theofficeexperts.com/for...read.php?t=4274 snice my post above.
In haste. Thanks. ScriptHam |
|
#5
|
|||
|
|||
|
Now Complete. Many thanks DougG. Have also discovered what an array node is. For details of how question was resolved see the link in the post above.
Is there a special way to sign off or mark a thread as complete? Good Luck ScriptHam |
|
#6
|
|||
|
|||
|
I come back & find out you got it working, I'm glad to see that! You don't need to do anything special when you're done with a thread.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > VBA - MS Outlook - Runtime Error: Array out of bounds |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|