Results 1 to 4 of 4

Thread: Email Template Fires Each Time You Receive a Fresh Email

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Administrator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,302
    Location
    How about:
    Private WithEvents inboxItems As Outlook.ItemsDim outlookApp As Outlook.Application
    
    Private Sub Application_Startup()
        Dim objectNS As Outlook.NameSpace
        Set outlookApp = Outlook.Application
        Set objectNS = outlookApp.GetNamespace("MAPI")
        Set inboxItems = objectNS.Folders("Shared Folder Name").Folders("Inbox").Items
    End Sub
    
    Private Sub inboxItems_ItemAdd(ByVal Item As Object)
        On Error GoTo ErrorHandler
        Dim Msg As Outlook.MailItem
        Dim MessageInfo
        Dim Sender_ As String
        Dim olmailtemp As Outlook.MailItem
        If TypeName(Item) = "MailItem" Then
            Set olmailtemp = outlookApp.CreateItemFromTemplate("location of oft file\Test.oft")
            With olmailtemp
                .Display
                .BodyFormat = olFormatHTML
                .To = Item.SenderEmailAddress
                .Subject = Item.Subject
                '.Send
            End With
        End If    
        ExitNewItem:
        Exit Sub
        ErrorHandler:
        MsgBox Err.Number & " - " & Err.Description
        Resume ExitNewItem
    End Sub
    Last edited by Aussiebear; 03-04-2025 at 02:17 PM.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2408, Build 17928.20080

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •