?
Solved

Outlook Macro to popup a box if a mail is receive on a particular folder...

Posted on 2007-10-02
22
Medium Priority
?
1,393 Views
Last Modified: 2008-01-09
Hi,

Outlook Macro to popup a box if a new mail is receive on a particular folder...

Is there a way to receive a popup on any mail that come in to a folder...

Regards
Sharath
0
Comment
Question by:bsharath
  • 11
  • 11
22 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 19997186
Hi, bsharath.

The answer depends on what type of box you have in mind.  Yes, it is possible to monitor a particualr folder and pop ip a dialog-box when an item is added to that folder.  But, that dialog-box won't be the same new message box that Outlook displays when an item is delivered.  And this only works for the full version of Outlook, not Outlook Express.  If you're interested, then I can post the code and instructions for using it.
0
 
LVL 11

Author Comment

by:bsharath
ID: 19997199
Hi,

I want it for Misrosoft Outlook ver 2007.I want a popup saying i have a new mail...
0
 
LVL 11

Author Comment

by:bsharath
ID: 19997209
Just wanted to know if you can help with this post...
http://www.experts-exchange.com/Programming/Languages/Scripting/Q_22864767.html
0
Technology Partners: 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!

 
LVL 76

Expert Comment

by:David Lee
ID: 20011213
I apologize for being slow.  Here's the code for doing this.  Follow these instructions to use it.

1.  Start Outlook.
2.  Click Tools->Macros->Visual Basic Editor.
3.  If not already expanded, expand Microsoft Office Outlook Objects and select ThisOutlookSession.
4.  Copy the code and paste it into the right-hand pane of the VB editor.
5.  Edit the code as desired.
6.  Click the diskette icon on the toolbar to save the code.
7.  Close the VB editor.
8  Follow these instructions to sign the macro: http://office.microsoft.com/en-us/help/HA012317811033.aspx
9.  Click Tools->Trust Center
10. Click Macro Security.
11. Ensure that Macro Security is set to "Warnings for signed macros; all unsigned macros are disabled"
12. Close Outlook.
13.  Start Outlook.

I want t remind you that the popup generated by this will NOT work like the notification messages generated by Outlook.  This will display a standard Windows dialog-box that will remian onscreen until you click a button.  The dialog-box will block other Outlook actions until you click its button.

Private WithEvents olkInbox As Outlook.Items

Private Sub Application_MAPILogonComplete()
    'Change the path on the following line to that of the folder you want to monitor
    Set olkInbox = OpenOutlookFolder("Folder\SubFolder").Inbox
End Sub

Private Sub Application_Quit()
    Set olkInbox = Nothing
End Sub

Private Sub olkInbox_ItemAdd(ByVal Item As Object)
    'Set the message on the following line as desired.
    MsgBox "Your message goes here."
End Sub

Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        olkFolder As Outlook.MAPIFolder
    On Error GoTo ehOpenOutlookFolder
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        If Left(strFolderPath, 1) = "\" Then
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        End If
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            If IsNothing(olkFolder) Then
                Set olkFolder = Session.Folders(varFolder)
            Else
                Set olkFolder = olkFolder.Folders(varFolder)
            End If
        Next
        Set OpenOutlookFolder = olkFolder
    End If
    On Error GoTo 0
    Exit Function
ehOpenOutlookFolder:
    Set OpenOutlookFolder = Nothing
    On Error GoTo 0
End Function
0
 
LVL 11

Author Comment

by:bsharath
ID: 20011542
Hi,

I need to change just these lines right

Set olkInbox = OpenOutlookFolder("Sharath").Inbox

    MsgBox "Your message goes here."

I have a folder called sharath.This has a rule that when a mail is sent to my self it comes to the folder.
Sharath is right below the Inbox.

Is the change correct.
I just tried but did not receive a popup.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20017797
The change is close, but not quite right.  Paths in Outlook are just like paths in the file system, except they don't involve drive letters.  The path to the folder you described is probably

    Mailbox - Your Mailbox Name\Inbox\Sharath

Also, I had a typo in my code.  The line should have read

    Set olkInbox = OpenOutlookFolder("Folder\SubFolder").Items

0
 
LVL 11

Author Comment

by:bsharath
ID: 20019476
Hi,

As the folder "Sharath" is in my Pst below the inbox..
Should i mention the Pstname\Inbox\sharath

Set olkInbox = OpenOutlookFolder("Pstname\Inbox\sharath").Items
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20022221
Yes.
0
 
LVL 11

Author Comment

by:bsharath
ID: 20022287
I get a  error here.


---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Sub or Function not defined
---------------------------
OK   Help  
---------------------------


Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder

This line looks like this...

Set olkInbox = OpenOutlookFolder("personal folder\inbox\Sharath").Item
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20024604
This line

    Set olkInbox = OpenOutlookFolder("personal folder\inbox\Sharath").Item

should end with "Items", plural, not "Item".
0
 
LVL 11

Author Comment

by:bsharath
ID: 20026364
I get this.

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Sub or Function not defined
---------------------------
OK   Help  
---------------------------

This line is highlitted.

Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20027549
Oops.  Looks like I missed one function when I pasted the code in.  Apologies!  Here it is.

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

Author Comment

by:bsharath
ID: 20028000
Hi,

Can i have the full code here please...
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 20028807
Ok.

Private WithEvents olkInbox As Outlook.Items

Private Sub Application_MAPILogonComplete()
    'Change the path on the following line to that of the folder you want to monitor
    Set olkInbox = OpenOutlookFolder("Folder\SubFolder").Inbox
End Sub

Private Sub Application_Quit()
    Set olkInbox = Nothing
End Sub

Private Sub olkInbox_ItemAdd(ByVal Item As Object)
    'Set the message on the following line as desired.
    MsgBox "Your message goes here."
End Sub

Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        olkFolder As Outlook.MAPIFolder
    On Error GoTo ehOpenOutlookFolder
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        If Left(strFolderPath, 1) = "\" Then
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        End If
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            If IsNothing(olkFolder) Then
                Set olkFolder = Session.Folders(varFolder)
            Else
                Set olkFolder = olkFolder.Folders(varFolder)
            End If
        Next
        Set OpenOutlookFolder = olkFolder
    End If
    On Error GoTo 0
    Exit Function
ehOpenOutlookFolder:
    Set OpenOutlookFolder = Nothing
    On Error GoTo 0
End Function

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

Author Comment

by:bsharath
ID: 20029481
Hi still does not popup.

I get this line in Red..
Private WithEvents olkInbox As Outlook.Items
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20030598
Is that line at the very top of the module, or is there code above it?  Is it in the correct module, ThisOutlookSession?  Did you insert the path to your folder?  
0
 
LVL 11

Author Comment

by:bsharath
ID: 20032003
Hi,

I have tried mentioning them path like this.
   Set olkInbox = OpenOutlookFolder("inbox\sharath").Inbox
like this.
   Set olkInbox = OpenOutlookFolder("personal folder\inbox\sharath").Inbox

Personal folder is the profile name
sharath is the outlook folder name

Is there any thing that i am doing wrong
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20034391
Inbox was a typo that I corrected several posts back.  It should be Items.
0
 
LVL 11

Author Comment

by:bsharath
ID: 20034440
Hi i tried this but still dont get a popup...
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20036771
I know the code works, I've tested it here, so there has to be something going on at your end.  Are you certain of the folder path?  That's the most likely cause I can think of.  Beyond that, please post the code you are using now so I can verify it.
0
 
LVL 11

Author Comment

by:bsharath
ID: 20038371
Hi,

When i go to properties of the folder"Sharath"
The location looks like this.

\\Personal Folders\Inbox

I even tried giving \\personal folder\inbox\sharath
still dont get an error or popup.
Is there any reference that i need to enable

When i try to play the macro i get this.

---------------------------
Microsoft Visual Basic
---------------------------
The macros in this project are disabled.  Please refer to the online help or documentation of the host application to determine how to enable macros.
---------------------------
OK   Help  
---------------------------
But the " No warning check for macro" is enabled.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 20045713
The first time a macro is run in Outlook you should get the message about macros being disabled, but you should be asked if you want to enable them.  I take it that isn't happening, right?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

809 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