vba - Error converting Excel range to Jpeg and inserting into Outlook -


i have code convert range in excel 2010 jpeg , insert outlook 2010. code converts range chart , creates jpeg. jpeg corrupted , show chart in background behind range attempting show. here example:

jpeg error

here code this:

sub mail_as_pic()  dim tempfilepath string dim outapp outlook.application dim outmail outlook.mailitem  on error resume next  kill tempfilepath & "quota.jpg"  dim sh worksheet set sh = sheets("strategic")      'create new microsoft outlook session     set outapp = createobject("outlook.application")     'create new message     set outmail = outapp.createitem(olmailitem)      outmail         .sentonbehalfofname = "me@me.com"         .display         .subject = "strategic sales"         .to = "me@me.com"         call createjpg("strategic", "a1:f11", "quota")         'this runs macro below , creates jpeg         tempfilepath = environ$("temp") & "\"         .attachments.add tempfilepath & "quota.jpg", olbyvalue, 0         'we attached embedded image position @ 0 (makes attachment hidden)         '.attachments.add          'then add html <img src=''> link image         'note can customize width , height - not mandatory          '<br><br> return or line space         .htmlbody = "<br>" _             & "attached please find strategic sales month." _             & "<br><br>" _             & "please reach out me questions." _             & "<br><br>" _             & "<img src='cid:quota.jpg'" & "width=width height=heigth><br><br>" _             & "<br><br>" _             & "thank you," _             & .htmlbody          .display         '.send     end  kill tempfilepath & "quota.jpg"  set sh = nothing set outapp = nothing set outmail = nothing   end sub  sub createjpg(namesheet string, namerange string, namefile string) thisworkbook.activate worksheets(namesheet).activate set plage = nothing 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 

i using code in several workbook, 1 of creates jpeg 2 separate ranges. 1 of conversions works every time, other creates , error every time. both converting data pivot table.

i've been trying solve time no luck. appreciated.

the issue created when trying convert more 1 table picture. solution create each table own jpeg, , insert each jpeg email.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -