?
Solved

Right click selected email and run macro then create the email with predefined text with an jpg file as attachment thet can be embedded into the body of the email.

Posted on 2010-01-12
7
Medium Priority
?
219 Views
Last Modified: 2012-05-08
Hi,

Right click selected email and run macro then create the email with predefined text with an jpg file as attachment thet can be embedded into the body of the email.

Send individual emails to just the Users whose names are in the TO box and do nothing with the CC names.

Regards
Sharath
0
Comment
Question by:bsharath
[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
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 26393701
Hi, Sharath.

I want to make sure I understand what you want.  You want to right-click a message and run a macro.  When the macro runs you want it to create a new message with predefined text in the body.  You also want to attach a .jpg file.  The message is then to be sent to all the "To" addressees in the original message.  Is that correct?  Assuming it is, does each addressee get their own copy of the message or id it one message addressed to all?
0
 
LVL 11

Author Comment

by:bsharath
ID: 26394876
Hi David,
Yes David you are right

I want each person to receive seperate email with his name in the body like

Hi His name,

Say i have an email from Xyz
To
Abc,DEF
CC to Me
When replies to it Abc,DEF are the persons the mail has to go...
0
 
LVL 76

Expert Comment

by:David Lee
ID: 26396503
The solution comes in two parts.  This is part #1.  Follow these instructions to add it to Outlook.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor

Sub PredefinedResponse()
    Dim olkItem As Outlook.MailItem, olkResponse As Outlook.MailItem, olkAddressee As Outlook.Recipient
    For Each olkItem In Application.ActiveExplorer.Selection
        For Each olkAddressee In olkItem.Recipients
            If olkAddressee.Type = olTo Then
                Set olkResponse = Application.CreateItem(olMailItem)
                With olkResponse
                    .Recipients.Add olkAddressee.Address
                    'Edit the message subject on the next line.'
                    .subject = "Your Subject"
                    'Edit the message body on the next line.'
                    .HTMLBody = "Your message."
                    'Edit the file name and path on the next line.'
                    .Attachments.Add "C:\eeTesting\MyImage.jpg"
                    .Display
                End With
            End If
        Next
    Next
End Sub

Open in new window

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: 26396512
This is part #2.  Follow these instructions to add it to Outlook.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comment lines wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Click Macro Security
10. Set Macro Security to "Warnings for all macros"
11. Click OK
12. Close Outlook
13. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

Because I know that you already have an ItemContextMenuDisplay subroutine with code in it, you will need to integrate this code into it.  If you simply add the code to waht you already have, then you'll get an ambiguous reference error.
Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As Office.CommandBar, ByVal Selection As Selection)
    Dim objButton As CommandBarButton
    Set objButton = CommandBar.Controls.Add(msoControlButton)
    With objButton
       .Style = msoButtonIconAndCaption
       'Enter your caption text'
       .Caption = "Send predefined response"
       'List of face IDs here: http://www.kebabshopblues.co.uk/2007/01/04/visual-studio-2005-tools-for-office-commandbarbutton-faceid-property/'
       .FaceId = 355
       'Enter the macro you want to run.  Be sure to include the Project and module names.'
       .OnAction = "Project1.Module81.PredefinedResponse"
   End With
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 26396730
Thanks David all perfect
I want the image to be embedded in the body
Like
=================================
Hi Username,

Image

Regards
Sharath
=================================
I want the above footer also please
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 26406127
Ok.  Repalce PredefinedResponse with the version below.
Sub PredefinedResponse()
    Dim olkItem As Outlook.MailItem, olkResponse As Outlook.MailItem, olkAddressee As Outlook.Recipient
    For Each olkItem In Application.ActiveExplorer.Selection
        For Each olkAddressee In olkItem.Recipients
            If olkAddressee.Type = olTo Then
                Set olkResponse = Application.CreateItem(olMailItem)
                With olkResponse
                    .Recipients.Add olkAddressee.Address
                    'Edit the message subject on the next line.'
                    .subject = "Your Subject"
                    'Edit the message body on the next line.'
                    .HTMLBody = "Hi " & olkAddressee.Name & ",<br><br><img src=""C:\eeTesting\MyImage.jpg"" /><br><br>Regards<br>Sharath"
                    .Display
                End With
            End If
        Next
    Next
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 26406185
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Mailbox Overload?
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

770 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