?
Solved

Drag and Drop autoresponse emails - In Outlook - More than one folder.

Posted on 2006-07-21
11
Medium Priority
?
294 Views
Last Modified: 2010-04-30
Relating to question... http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_21916262.html

Would like to change this code so I can use 3 seperate folders, with 3 seperate template replies.

Private WithEvents olkFolder As Outlook.Items

Private Sub Application_Startup()
    'Change the path of the folder to watch
    Set olkFolder = OpenMAPIFolder("\FolderName\SubFolderName").Items
End Sub

Private Sub Application_Quit()
    Set olkFolder = Nothing
End Sub

Private Sub olkFolder_ItemAdd(ByVal Item As Object)
    Dim olkMessage As Outlook.MailItem
    Set olkMessage = Application.CreateItem(olMailItem)
    With olkMessage
        .Recipients.Add Item.SenderEmailAddress
        'Change the subject as desired
        .Subject = "My Subject"
        'Change the message format as desired
        .BodyFormat = olFormatHTML
        'Change the message body as desired
        .HTMLBody = "My message"
        .Send
    End With
    Set olkMessage = Nothing
End Sub

'Credit where credit is due.
'The code below is not mine.  I found it somewhere on the internet but do
'not remember where or who the author is.  The original author(s) deserves all
'the credit for these functions.
Function OpenMAPIFolder(szPath)
    Dim app, ns, flr, szDir, i
    Set flr = Nothing
    Set app = CreateObject("Outlook.Application")
    If Left(szPath, Len("\")) = "\" Then
        szPath = Mid(szPath, Len("\") + 1)
    Else
        Set flr = app.ActiveExplorer.CurrentFolder
    End If
    While szPath <> ""
        i = InStr(szPath, "\")
        If i Then
            szDir = Left(szPath, i - 1)
            szPath = Mid(szPath, i + Len("\"))
        Else
            szDir = szPath
            szPath = ""
        End If
        If IsNothing(flr) Then
            Set ns = app.GetNamespace("MAPI")
            Set flr = ns.Folders(szDir)
        Else
            Set flr = flr.Folders(szDir)
        End If
    Wend
    Set OpenMAPIFolder = flr
End Function

Function IsNothing(obj)
  If TypeName(obj) = "Nothing" Then
    IsNothing = True
  Else
    IsNothing = False
  End If
End Function

I had a go myself but couldn't get it to work.
0
Comment
Question by:Antonio King
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 

Author Comment

by:Antonio King
ID: 17152525
Sorry the three folders can be called folder1, folder2 and folder3. I can change these.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1000 total points
ID: 17152750
Good morning, Alan-Yeo.  

That's pretty simple.  Only requires a minimal change.  

Private WithEvents olkFolder1 As Outlook.Items, _
    WithEvents olkFolder2 As Outlook.Items, _
    WithEvents olkFolder3 As Outlook.Items

Private Sub Application_Startup()
    'Change the path of the folder to watch
    Set olkFolder1 = OpenMAPIFolder("\FolderName\SubFolderName").Items
    Set olkFolder2 = OpenMAPIFolder("\FolderName\SubFolderName").Items
    Set olkFolder3 = OpenMAPIFolder("\FolderName\SubFolderName").Items
End Sub

Private Sub Application_Quit()
    Set olkFolder1 = Nothing
    Set olkFolder2 = Nothing
    Set olkFolder3 = Nothing
End Sub

Private Sub olkFolder1_ItemAdd(ByVal Item As Object)
    Dim olkMessage As Outlook.MailItem
    Set olkMessage = Application.CreateItem(olMailItem)
    With olkMessage
        .Recipients.Add Item.SenderEmailAddress
        'Change the subject as desired
        .Subject = "My Subject"
        'Change the message format as desired
        .BodyFormat = olFormatHTML
        'Change the message body as desired
        .HTMLBody = "My message"
        .Send
    End With
    Set olkMessage = Nothing
End Sub

Private Sub olkFolder2_ItemAdd(ByVal Item As Object)
    Dim olkMessage As Outlook.MailItem
    Set olkMessage = Application.CreateItem(olMailItem)
    With olkMessage
        .Recipients.Add Item.SenderEmailAddress
        'Change the subject as desired
        .Subject = "My Subject"
        'Change the message format as desired
        .BodyFormat = olFormatHTML
        'Change the message body as desired
        .HTMLBody = "My message"
        .Send
    End With
    Set olkMessage = Nothing
End Sub

Private Sub olkFolder3_ItemAdd(ByVal Item As Object)
    Dim olkMessage As Outlook.MailItem
    Set olkMessage = Application.CreateItem(olMailItem)
    With olkMessage
        .Recipients.Add Item.SenderEmailAddress
        'Change the subject as desired
        .Subject = "My Subject"
        'Change the message format as desired
        .BodyFormat = olFormatHTML
        'Change the message body as desired
        .HTMLBody = "My message"
        .Send
    End With
    Set olkMessage = Nothing
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17152754
Leave the OpenMAPIFolder() and IsNothing() as they are.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Antonio King
ID: 17152823
superb, I tried something simliar to the above but mine didnt work :|

Anyway, this will be roled out across our company, just worried people might drop the emails into the wrong folder, which means a rejection email could be sent to them.

Could you possibly do me another script that will ask a confirmation message...

"Are you sure you want to send an application accept email to.... <RECEIPIENT>"

If the user clicks no could the email that was dropped into the folder be moved back to the inbox?

Many thanks! you've been most helpful.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17153348
No problem.  Change each of olkFolder_ItemAdd subs to look like this:

Private Sub olkFolder1_ItemAdd(ByVal Item As Object)
    Dim olkMessage As Outlook.MailItem
    If MsgBox("Are you sure you want to send an application accept email to " & Item.SenderEmailAddress & "?", vbYesNo, "Confirm Send") = vbYes Then
        Set olkMessage = Application.CreateItem(olMailItem)
        With olkMessage
            .Recipients.Add Item.SenderEmailAddress
            'Change the subject as desired
            .Subject = "My Subject"
            'Change the message format as desired
            .BodyFormat = olFormatHTML
            'Change the message body as desired
            .HTMLBody = "My message"
            .Send
        End With
    End If
    Set olkMessage = Nothing
End Sub
0
 

Author Comment

by:Antonio King
ID: 17153546
BlueDevilFan you legend.

Many thanks for your help.
0
 

Author Comment

by:Antonio King
ID: 17153647
Just tested the script, works a charm except it doesn't seem to move the email back to the inbox if you select no?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17157281
Sorry, I missed that part.  Use this version instead.

Private Sub olkFolder1_ItemAdd(ByVal Item As Object)
    Dim olkMessage As Outlook.MailItem
    If MsgBox("Are you sure you want to send an application accept email to " & Item.SenderEmailAddress & "?", vbYesNo, "Confirm Send") = vbYes Then
        Set olkMessage = Application.CreateItem(olMailItem)
        With olkMessage
            .Recipients.Add Item.SenderEmailAddress
            'Change the subject as desired
            .Subject = "My Subject"
            'Change the message format as desired
            .BodyFormat = olFormatHTML
            'Change the message body as desired
            .HTMLBody = "My message"
            .Send
        End With
    Else
        Item.Move Session.GetDefaultFolder(olFolderInbox)
    End If
    Set olkMessage = Nothing
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17220753
Any update, Alan-Yeo?
0
 

Author Comment

by:Antonio King
ID: 17221791
Oh sorry!

That worked perfectly, cheers!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17222096
No problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question