Log in

View Full Version : Outlook Vba Newmail Help



ahmedv
09-25-2007, 11:22 PM
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

Oorang
09-27-2007, 01:11 PM
Untested, but this should do it for you.
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

ahmedv
10-01-2007, 01:34 AM
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

:dunno

Oorang
10-01-2007, 03:40 PM
That is what this line does:
VBA.SendKeys "^+p", True

ahmedv
10-01-2007, 10:53 PM
Plugged that code in, still not working, however if i manually press the keys they work, any other idea's

Oorang
10-02-2007, 07:20 AM
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?

ahmedv
10-07-2007, 10:41 PM
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

Oorang
10-08-2007, 06:21 AM
vba.shell "C:\MyPath\MyExe.exe"