Re:Running a Macro when email arrives

Status
Not open for further replies.
G

Gardos Catalin

Hello everybody. I trie to make a macro that print my incoming email that

contains in subject word "Comanda online".

This is the macro:

Private Sub Application_NewMail()

CheckMail

End Sub

Public Sub CheckMail()

Dim OlApp As Outlook.Application

Dim Inbox As Outlook.MAPIFolder

Dim oOApp As Outlook.Application

Dim oOMail As Outlook.MailItem

Dim InboxItems As Outlook.Items

Dim Mailobject As Object

Dim Subject As String

Set OlApp = CreateObject("Outlook.Application")

Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)

Set InboxItems = Inbox.Items

For Each Mailobject In InboxItems

If Mailobject.UnRead Then

Subject = Mailobject.Subject

If Subject = "Comanda online" Then

Mailobject.PrintOut

End If

Mailobject.UnRead = False

End If

Next

Set OlApp = Nothing

Set Inbox = Nothing

Set InboxItems = Nothing

Set Mailobject = Nothing

End Sub

It's working, but i want to print only the body of the email.

Is this possible ?

Thank you.

Hope to reply to me.

url:http://www.ureader.com/msg/1081942.aspx
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Re: Running a Macro when email arrives

I'd probably create a Word document, insert the body of the email, and then

print the document instead of the email.

Best regards

Michael Bauer

Am Mon, 4 Jan 2010 12:52:58 +0800 schrieb Gardos Catalin:


> Hello everybody. I trie to make a macro that print my incoming email that
> contains in subject word "Comanda online".
> This is the macro:

> Private Sub Application_NewMail()

> CheckMail

> End Sub

> Public Sub CheckMail()
> Dim OlApp As Outlook.Application
> Dim Inbox As Outlook.MAPIFolder
> Dim oOApp As Outlook.Application
> Dim oOMail As Outlook.MailItem
> Dim InboxItems As Outlook.Items
> Dim Mailobject As Object
> Dim Subject As String

> Set OlApp = CreateObject("Outlook.Application")
> Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
> Set InboxItems = Inbox.Items
> For Each Mailobject In InboxItems
> If Mailobject.UnRead Then
> Subject = Mailobject.Subject
> If Subject = "Comanda online" Then
> Mailobject.PrintOut
> End If
> Mailobject.UnRead = False
> End If
> Next

> Set OlApp = Nothing
> Set Inbox = Nothing
> Set InboxItems = Nothing
> Set Mailobject = Nothing
> End Sub

> It's working, but i want to print only the body of the email.
> Is this possible ?

> Thank you.
> Hope to reply to me.

> url:http://www.ureader.com/msg/1081942.aspx
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G email returns after running macro to move emails Outlook VBA and Custom Forms 1
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
B Automation error running VB macro code Outlook VBA and Custom Forms 8
P Outlook Macro keeps running for the same messagage Using Outlook 2
E Word macro running from OL VBA throwing error on Word SaveAs?? Outlook VBA and Custom Forms 8
A VBscript stops running after updating form Outlook VBA and Custom Forms 1
N contact notepad 'style' getting changed after clicking and running Activities Using Outlook 2
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
S Problem running Command button code Outlook VBA and Custom Forms 2
Diane Poremsky OUTLOOK.EXE continues running after you exit Outlook Using Outlook 0
Diane Poremsky Running Outlook Macros on a Schedule Using Outlook 0
B ActiveExplorer return NULL on new Window user login and running Outlook first time Using Outlook 1
JorgeDario Template oft that contains VBScript Is not running Using Outlook 1
M Mark Complete keyboard shortcut... on a mac running Windows Bootcamp Using Outlook 0
N Outlook 2007 To-Do-List status keeps running Using Outlook 2
S The attempted operation failed ... 2nd time running code Outlook VBA and Custom Forms 3
N Running multiple macros upon sending Outlook VBA and Custom Forms 6
M Accessing BCM with Excel / Running Reports BCM (Business Contact Manager) 1
G Error when running scanpst.exe Using Outlook 1
V Running scripts with Outlook 2013 Using Outlook 17
D Stopping "do you want to continue running scripts on this page" warnings Using Outlook 4
M Running macros in tasks sent out as meeting requests in invitees machine Using Outlook 4
N Rules stop running automatically Using Outlook 10
D VBA code running on Server? Shared mailbox email routing Using Outlook 3
T WAB editing: To help prevent malicious code from running.......... Using Outlook 18
M Outlook.exe 1.2Gb memory usage if running certain BCM reports BCM (Business Contact Manager) 8
M Why rules stop running automatically? Using Outlook 1
V Trouble Running Outlook 2007 and 2010 Using Outlook 4
S CSCANPST To Automate Running SCANPST.EXE Using Outlook 1
L remove a hotmail account from Outlook 2007 running on Vista home premium Using Outlook.com accounts in Outlook 1
S Outlook 2007 Running on Windows 7 hangs on send Using Outlook 7
A running code after the new inspector is visible Outlook VBA and Custom Forms 1
M Running Outlook as Scheduled task Outlook VBA and Custom Forms 1
S ActiveExplorer return NULL on new Window user login and running Outlook first time Outlook VBA and Custom Forms 19
A Running Code in Side by side calendar view Outlook VBA and Custom Forms 2
D Running a Program from Custom Action Rule Outlook VBA and Custom Forms 1
O Scheduled Task Fails running Code to send Outlook Mail from Excel. Outlook VBA and Custom Forms 9
B Phantom VBA Running Outlook VBA and Custom Forms 1
G To Prevent Malicious Code from running, one or more objects in thi BCM (Business Contact Manager) 2
M If loop not running Outlook VBA and Custom Forms 1
D Troubleshooting rule/script not running Outlook VBA and Custom Forms 5
P How to use a form from a rule running on the inbox Outlook VBA and Custom Forms 1
S To help prevent malicious code from running, one or more objects in this form were not loaded. For m Outlook VBA and Custom Forms 1
Q Running the Database from a Server BCM (Business Contact Manager) 7
N Running Code before Access 2007 closes down Outlook VBA and Custom Forms 1
S Outlook rules not running automatically Using Outlook 11
J Macro to Insert a Calendar Outlook VBA and Custom Forms 0
W Macro to Filter Based on Latest Email Outlook VBA and Custom Forms 6
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
D Autosort macro for items in a view Outlook VBA and Custom Forms 2

Similar threads

Top