locked
Trigger Excel macro on receiving Email RRS feed

  • Question

  • Hi,

    I am trying to run a Excel macro that is in my Personal.xlsb, on receiving an Email with the specific subject. I am new to Outlook VBA and I started by simply trying to save the attachment in the Email with the specific subject. I am not getting any error but the file is not getting saved. I have included the code am using to test. It would be helpful if someone could help me identify the issue(I have enabled macro trust settings). Thanks

    Private Sub Application_NewMail()

    Dim onamespace As Outlook.NameSpace
    Set onamespace = Outlook.GetNamespace("MAPI")

    Dim myfol As Outlook.Folder
    Set myfol = onamespace.GetDefaultFolder(olFolderInbox)

    Dim omail As Outlook.MailItem
    Set omail = Outlook.CreateItem(olMailItem)
    Dim atmt As Outlook.Attachment

    If omail.Subject = "Intimate" Then

        atmt.SaveAsFile "C:\" & atmt.FileName

    Else
    End If

    End Sub


    Saturday, December 12, 2020 10:15 PM