MS Outlook Macro

GarthZAR

New Member
Joined
Jun 8, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have a MS outlook macro that save all the files in specific folder, after what the reference number [folder number] should be, but I would like to run the macro only for unread emails in specific email folder. Need help setting up unread emails macro to start another macro.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi @GarthZAR

Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

You did not put your macro, I attach an example to see if it helps you and you can adapt it to your macro.

Rich (BB code):
Sub LeerCorreo()
    Dim olApp As Outlook.Application
    Dim objNS As Outlook.Namespace
    Dim olFolder As Outlook.MAPIFolder
    Dim msg As Outlook.MailItem
    '
    Application.ScreenUpdating = False
    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
    i = 2
    Columns("A:C").Clear
    On Error Resume Next
    For Each msg In olFolder.Items
        If msg.UnRead = True Then
            'msg.UnRead = False
            Cells(i, "A") = msg.SenderName
            Cells(i, "B") = msg.Subject
            Cells(i, "C") = msg.body
            i = i + 1
        End If
    Next
    Columns("A:C").WrapText = False
    Application.ScreenUpdating = True
    MsgBox "Fin"
End Sub

--------------
I hope it helps you.
Respectfully
Dante Amor
--------------​
 
Upvote 0
Solution
Hi @GarthZAR

Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

You did not put your macro, I attach an example to see if it helps you and you can adapt it to your macro.

Rich (BB code):
Sub LeerCorreo()
    Dim olApp As Outlook.Application
    Dim objNS As Outlook.Namespace
    Dim olFolder As Outlook.MAPIFolder
    Dim msg As Outlook.MailItem
    '
    Application.ScreenUpdating = False
    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")
    Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
    i = 2
    Columns("A:C").Clear
    On Error Resume Next
    For Each msg In olFolder.Items
        If msg.UnRead = True Then
            'msg.UnRead = False
            Cells(i, "A") = msg.SenderName
            Cells(i, "B") = msg.Subject
            Cells(i, "C") = msg.body
            i = i + 1
        End If
    Next
    Columns("A:C").WrapText = False
    Application.ScreenUpdating = True
    MsgBox "Fin"
End Sub

--------------
I hope it helps you.
Respectfully
Dante Amor
--------------​
Hi Dante
Thanks for the code. I will amend to fit.
Enjoy the weekend.
 
Upvote 0

Forum statistics

Threads
1,215,155
Messages
6,123,335
Members
449,098
Latest member
thnirmitha

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