Mark Inbox Messages As Unread

Divakarkumar

New Member
Joined
Jul 31, 2020
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have made below code mark read emails to unread status in the outlook but it will work only 11 iteration then it give the data type mismatch of item.

Not sure why i am getting this error, if some help on this would great.


Sub MarkInboxMessagesAsUnread()

Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Dim item As Outlook.MailItem

i = 1

Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox)


For Each item In Folder.Items

item.UnRead = True

Next item

Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing


End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try these modifications:
1) Modify this Dim:
VBA Code:
Dim Item As Object              '<<< New type

2) replace this block:
For Each item In Folder.Items
item.UnRead = True
Next item

with this:
Code:
For Each Item In Folder.Items
If Item Is MailItem Then
    Item.UnRead = True
End If
Next Item

Bye
 
Upvote 0
Thanks you so much Sir

It is working without if block if I add "If Item Is MailItem Then" I am getting error "Run-time error 424 object required"

May I know what Mailltem is referring
 
Upvote 0
Hummm... Your answer is a little bit cryptic...
So now you have a Run-time error 424? Which intruction generate it? (enter Debug, then report which is the hoghlighted instruction)
Could you also resume the complete macro?

"is MailItem" checks that the item you pick from the Folder is an email (not a report, a calendar item, a read confirmation, and I don't know what else the folder can contain)

Also "Item" is a keyword of vba; may I suggest you avoid using Item for one of your variable? I simply would use myItem.

Bye
 
Upvote 0
Solution

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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