Excel Hints

Results 1 to 8 of 8

Thread: Outlook Vba Newmail Help

  1. #1

    Outlook Vba Newmail Help

    Good day,

    Im looking for some help for a macro for Oulook 2003.

    Basically I need the macro to check for new mail with a certain specified subject, thereafter i need the macro to copy to the clipboard the content of the email, and therafter once the message is copied to auto press CTRL+SHIFT+P - to launch one of my other applications.

    Any idea's - im a bit new to VBA so any help would be appreciated
    Thanks
    Ahmed

  2. #2
    Untested, but this should do it for you.
    [vba]Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Const strKeyPhrase_c As String = "Foo"
    Const strDlmtr_c As String = ","
    Dim mai As Outlook.MailItem
    'MUST SET REFERENCE TO: C:\WINDOWS\system32\FM20.dll '
    Dim cb As MSForms.DataObject
    Dim varEntryIDs As Variant
    Dim varEID As Variant
    Set cb = New MSForms.DataObject
    varEntryIDs = VBA.Split(EntryIDCollection, strDlmtr_c, compare:=vbBinaryCompare)
    For Each varEID In varEntryIDs
    Set mai = Application.Session.GetItemFromID(varEID)
    If VBA.InStrB(mai.Subject, strKeyPhrase_c, compare:=vbTextCompare) Then
    cb.SetText mai.Body
    cb.PutInClipboard
    VBA.SendKeys "^+p", True
    End If
    Next
    End Sub
    [/vba]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3

    Thanks

    Thanks,

    I got it to run, the only problem im having now is the SendKeys

    I require the keys Ctrl+Shift+P to be pressed as a last step - any advise?

    Thanks


  4. #4
    That is what this line does:
    [VBA]VBA.SendKeys "^+p", True[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  5. #5
    Plugged that code in, still not working, however if i manually press the keys they work, any other idea's

  6. #6
    Hmmm probabbly need a different way to trigger. Sendkeys you have to get just right. Is ctrl-shift-p triggering another vba script? If not what is it triggering?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  7. #7
    Its not triggering anything, tried to change the keys as well, no luck

    mmm how can i launch an .exe from the application, possible i can launch the app and then try?

    Thanks

  8. #8
    vba.shell "C:\MyPath\MyExe.exe"
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

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