Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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.

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
bsharath
Asked:
bsharath
  • 4
  • 3
1 Solution
 
David LeeCommented:
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
 
bsharathAuthor Commented:
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
 
David LeeCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
David LeeCommented:
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
 
bsharathAuthor Commented:
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
 
David LeeCommented:
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
 
bsharathAuthor Commented:
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now