vba - How to copy text and charts in an Excel sheet to Outlook body? -
i trying copy text (constant range of cells) , charts in excel sheet outlook body, far succeeded in copying charts not text. want know best way copy both text (in selected range) , charts excel sheet outlook message. below code using now. code paste text charts overlapped on text (when charts pasted in email body). how can format outlook email , paste text , charts without overlapping.
sub email_charts(sfilename, subject1) dim r integer dim o outlook.application dim m outlook.mailitem dim weditor word.document set o = new outlook.application dim olto string windows("daily_status_macro_ver3.0.xlsm").activate sheets("main").select olto = worksheets("main").cells(3, 3).value windows(sfilename).activate msg = "<html><font face = calibri =2>" msg = msg & "hi all, <br><br>" msg = msg & "please find daily status below " msg = msg & "<b><font color=#0033cc>" msg = msg & sheets(1).range("b2:b4") set m = o.createitem(olmailitem) m.to = olto m.subject = subject1 m.bodyformat = olformathtml m.htmlbody = msg m.display windows(sfilename).activate sheets(1).select activesheet.drawingobjects.select selection.copy set weditor = o.activeinspector.wordeditor m.body = msg weditor.application.selection.paste 'm.send workbooks(sfilename).close savechanges:=false end sub
perhaps this:
sub createjpg(namesheet string, namerange string, namefile string) thisworkbook.activate worksheets(namesheet).activate set plage = thisworkbook.worksheets(namesheet).range(namerange) plage.copypicture thisworkbook.worksheets(namesheet).chartobjects.add(plage.left, plage.top, plage.width, plage.height) .activate .chart.paste .chart.export environ$("temp") & "\" & namefile & ".jpg", "jpg" end worksheets(namesheet).chartobjects(worksheets(namesheet).chartobjects.count).delete set plage = nothing end sub and within existing code:
set appoutlook = createobject("outlook.application") 'create new message set message = appoutlook.createitem(olmailitem) message .htmlbody = "hello" ' , whatever else need in text body 'first create image jpg file call createjpg("dashboard", "b8:h9", "dashboardfile") 'we attached embedded image position @ 0 (makes attachment hidden) tempfilepath = environ$("temp") & "\" .attachments.add tempfilepath & "dashboardfile.jpg", olbyvalue, 0 'then add html <img src=''> link image 'note can customize width , height - not mandatory .htmlbody = .htmlbody & "<br><b>weekly repport:</b><br>" _ & "<img src='cid:dashboardfile.jpg'" & "width='814' height='33'><br>" _ & "<br>best regards,<br>ed</font></span>" .to = "contact1@email.com; contact2@email.com" .cc = "contact3@email.com" .display '.send end
Comments
Post a Comment