Saturday, 20 March 2021

How to add image on Mail body with Macro.

 How to add image on Mail body with Macro.


नमस्कार दोस्तों , आज हम सीखेंगे के ईमेल बॉडी पे इमेज को कैसे ऐड करते हैं, Macro की मदद से । 


तो चलिए शुरू करते है आज का हमारा ये टॉपिक। 

दोस्तों कई  बार हमें email बनाकर excel  के रेंज को Email body  पे image  के रूप पे ऐड करना पड़ता है। 

तो दोस्तों excel  के रेंज को Edited range  की जगह इमेज को ऐड करना है तो इसके लिए हम macro  की मदद से कर सकते है , इस के लिए इस पोस्ट को  ध्यान से पढियेगा। 


इसे समझने में और आसानी हो इसके लिए मेल साथ में Excel attached  कर रहा हु आप उसे  download करके भी सिख सकते है। 

एक्सेल को डाउनलोड करने के लिए क्लिक करे  DOWNLOAD EXCEL 

जल्दी से एक्सेल को download कजिये तो आपको Macro को समझने में या फिर अपने एक्सेल में apply  करने में कोई दिक्कत नहीं होगी, और साथ में आप macro Coding को भी सिख जाओगे। 


Excel  ओपन करके Macro  code को open कीजिये।  (Shortcut ALT +F11)


निचे दिए हुए कोड बहुत ही important  है , इसलिए इसको पहले समझ लेते है। 

हम पहले एक्सेल की वो रेंज जिसको हमे image में convert करना है, उसे RangeToPublish  नाम दे देते है। 

और उसे Set कर देते है के वो RangeToPublish को Macro इमेज में कन्वर्ट करे। 


सबसे पहले हम इसे define कर देते है। 

Dim RangeToPublish As Range


Set RangeToPublish = Sheets("ImageonMailbody").Range("A1:E21")

दोस्तों Sheets("ImageonMailbody") में से  "ImageonMailbody" को replace कर दो अपने एक्सेल sheet के नाम से। 


और RangeToPublish को Image  में convert करने के लिए Macro Code है। 

RangeToPublish.CopyPicture appearance:=xlScreen, Format:=xlBitmap



 यहाँ पे हमारा आधा काम पूरा हो गया।  क्यूंकि हमने एक्सेल range  को Bitmap याने के Image  में कन्वर्ट करने का code ड़ाल दिया। 



Outlook  mail  Body को सेट कैसे करेंगे। 

अब देखते है, की Email की Body कैसे बनाये और उसपे इमेज को कैसे Set and  add  करे। 

तो चलो Outlook Email ओपन करते है Macro के Coding  से। 

Dim OutApp As Object, NewMail As Object


Set OutApp = CreateObject("Outlook.application")

Set NewMail = OutApp.Createitem(0)


ऊपर दिया हुआ Macro  का ये छोटा सा कोड अपने को Outlook Application  open करने में मदद करेगा। 


With NewMail
 .To = "आपका मेल Id जीसे मेल भेजना है "
 .Subject = "Send Mail with Image on the MailBody"
 
 .Htmlbody = "<body> Hello Team,<br/><br/>" & _
            " Please find below Image screenshot of data. <br/><br/><br/>" & _
            "<br/> Regards,<br/>Excel_Samadhaan</body>"
.display

इस कोड से Macro  आपको Email  का Page ओपन करेगा और आपका जो भी ईमेल फॉर्मेट है उसे display  कर देगा। 


Image को Outlook  के Mail Body  पे कैसे add  करेंगे 

दोस्तों, अब बारी आती है के हम Email body पे Image को कैसे Add करेंगे।  


Dim xinspect As Object, pageeditor As Object

Set xinspect = NewMail.getinspector

Set pageeditor = xinspect.wordeditor


pageeditor.Application.Selection.Start = Len(.Htmlbody)

pageeditor.Application.Selection.End = pageeditor.Application.Selection.Start - 26

pageeditor.Application.Selection.pasteandformat (wdformatplaintext)


दोस्तों इस Code को बहुत ही ध्यान से सीखिए क्यूंकि यही Code  है जो इस  पोस्ट का सबसे ज्यादा important Code  है जो हमें अपने Outlook  के Mail Body पे Image को सेट करेगा और Add भी करेगा। 

pageeditor.Application.Selection.End = pageeditor.Application.Selection.Start - 26

इस कोड में जो Number दिया है उसे हमें सेट करना पड़ेगा अपने Signature के हिसाब से। याने के अगर आपका signature है "Regards, Samadhan Gawle" तो इसका Len याने की Spelling Count है 23 Letters .. 

उस हिसाब से ही हमने signature के ऊपर भी 3 space को Add  कर दिया ताकि Signature और Image  में space बने। 


निचे दिया हुआ इमेज चेक करे। 



आपके लिए में पूरा Macro Coding Niche पेस्ट कर देता हु आप इसे Copy , Paste  करे अपने Excel  के Coding में। 



Sub Send_Mail_With_Screenshot_On_MailBody()

    Dim RangeToPublish As Range

    Dim OutApp As Object, NewMail As Object


Set RangeToPublish = Sheets("ImageonMailbody").Range("A1:E21")

RangeToPublish.CopyPicture appearance:=xlScreen, Format:=xlBitmap


Set OutApp = CreateObject("Outlook.application")

Set NewMail = OutApp.Createitem(0)


With NewMail

 .To = "Samadhaangawle@gmail.com"

 .Subject = "Send Mail with Image on the MailBody"

  .Htmlbody = "<body> Hello Team,<br/><br/>" & _

            " Please find below Image screenshot of data. <br/><br/><br/>" & _

            "<br/> Regards,<br/>Excel_Samadhaan</body>"

.display


Dim xinspect As Object, pageeditor As Object

    Set xinspect = NewMail.getinspector

    Set pageeditor = xinspect.wordeditor


pageeditor.Application.Selection.Start = Len(.Htmlbody)

pageeditor.Application.Selection.End = pageeditor.Application.Selection.Start - 26

pageeditor.Application.Selection.pasteandformat (wdformatplaintext)


    Set pageeditor = Nothing

    Set pageinspector = Nothing

End With

    Set OutApp = Nothing

    Set NewMail = Nothing

End Sub


featured Post

Recurring Deposite

  https://tax2win.in/guide/5-year-post-office-recurring-deposit

About Me

My photo
Kalyan, Mumbai, Maharashtra, India

Quick Search Formula