Outlook error, Pls Help

RompStar

Well-known Member
Joined
Mar 25, 2005
Messages
1,200
I am using this code in outlook, and it's crashing. I took over process for someone else, not outlook VBA expert, any ideas ?

The error is here:

Set myinboxfolder = myInbox.Folders(3)

Run-time error '-2147352567 (80020009)';
Array index out of bounds

Any idea ?




Sub ExportAll()

' copies every messages from the IN Box and
Dim Message As MailItem

Set myNameSpace = Application.GetNamespace("MAPI")

Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)

Set myinboxfolder = myInbox.Folders(3)

For Each Message In myinboxfolder.Items

Message.Categories = "CCG Job"

Message.Save

Next Message

End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
This means that you have at most 2 folders within your Inbox. You may have none. Before referring to the 3rd folder, you should check the
Code:
myinboxfolder.Folders.Count
property and act accordingly. The folders collection is 1 based, by the way.
 
Upvote 0

Forum statistics

Threads
1,225,478
Messages
6,185,228
Members
453,283
Latest member
Shortm88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top