Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-07-21
11
Medium Priority
?
296 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
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.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

597 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