Writing macros in Outlook

akhendre88

Board Regular
Joined
Sep 17, 2015
Messages
76
Can we write macros directly into Outlook or do we have to write the same in excel and then activate the reference to the Outlook object library?

Thank you,

Akshay
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You can write macros in Outlook. Just press [Alt]+[F11] in Outlook to bring up the VBA editor there.

WBD
 
Upvote 0
Thank you for your reply.

Actually I am aware of that. But I saw some macros of reading the content of mail from outlook. In which the person had asked to write the macro in excel and then refer it using outlook library.

So if we can do it directly in the outlook, where can we save the content of an email?

Thank you
 
Upvote 0
Here is what I am trying to do.

Every hour I am getting an email alerts which have number of failure of some process. So I want to read an email using macro and if the number of failures are greater than some threshold value, I want to generate the msgbox in outlook stating that an email received at [whatever the time] have this much of failures. So any idea how can I do this.

Thank you,

Akshay
 
Upvote 0
I don't think you're in the right place. This is the Mr. Excel forum; you need some Outlook experts. Not sure you'll find many here.

WBD
 
Upvote 0
Below is what I tried and it is working for me.
Code:
Sub chnageFolder()
    Dim ns As Outlook.NameSpace
    Dim exp As Outlook.Explorer
    Dim myInbox As Folder, folder1 As Folder, folder2 As Folder
    Dim myOlItems As Outlook.Items
    Dim mItem As Outlook.mailItem
    Dim strBody As String
        
    Set ns = Application.GetNamespace("MAPI")
    Set exp = Application.ActiveExplorer
    
    'Accessing the Inbox
    Set myInbox = ns.GetDefaultFolder(olFolderInbox)
    
    'Changing the current folder from inbox to File Size
    Set folder1 = myInbox.Folders.Item("Alerts").Folders.Item("File Size")
    Set exp.CurrentFolder = folder1

    If (folder1.Items(1).UnRead = True) Then
        With folder1.Items(1)
            MsgBox .Body
        End With
    End If
                        
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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