How to keep formats when I copy a range from Excel to outlook -


hello have excel table formats 10(red) -> 15(green), @ end loose formats have in excel. use next code send , email range outlook

sub email()      dim outapp object     dim outmail object     dim fname string     dim hoja string     dim rng range     dim celdas string      set outapp = createobject("outlook.application")     set outmail = outapp.createitem(0)      set rng = range("c3:q22")     on error resume next     outmail          .to = "juan"         .cc = "maria"         .bcc = ""         .subject = "xxxx"         .htmlbody = "hey" & rangetohtml(rng)          .display   'or use .display     end     on error goto 0      'kill fname     set outmail = nothing     set outapp = nothing  end sub 

and next function, copied next link how send mails excel

function rangetohtml(rng range) ' changed ron de bruin 28-oct-2006 ' working in office 2000-2010     dim fso object     dim ts object     dim tempfile string     dim tempwb workbook      tempfile = environ$("temp") & "/" & format(now, "dd-mm-yy h-mm-ss") & ".htm"      'copy range , create new workbook past data in     rng.copy     set tempwb = workbooks.add(1)     tempwb.sheets(1)         .cells(1).pastespecial paste:=8         .cells(1).pastespecial xlpastevalues, , false, false         .cells(1).pastespecial xlpasteformats, , false, false         .cells(1).select         application.cutcopymode = false         on error resume next         .drawingobjects.visible = true         .drawingobjects.delete         on error goto 0     end      'publish sheet htm file     tempwb.publishobjects.add( _          sourcetype:=xlsourcerange, _          filename:=tempfile, _          sheet:=tempwb.sheets(1).name, _          source:=tempwb.sheets(1).usedrange.address, _          htmltype:=xlhtmlstatic)         .publish (true)     end      'read data htm file rangetohtml     set fso = createobject("scripting.filesystemobject")     set ts = fso.getfile(tempfile).openastextstream(1, -2)     rangetohtml = ts.readall     ts.close     rangetohtml = replace(rangetohtml, "align=center x:publishsource=", _                           "align=left x:publishsource=")      'close tempwb     tempwb.close savechanges:=false      'delete htm file used in function     kill tempfile      set ts = nothing     set fso = nothing     set tempwb = nothing end function 

ok found how made it, in rangetohtml(), when pasting values changed code for:

    tempwb.sheets(1)         '.cells(1).pastespecial paste:=8         .cells(1).pastespecial         '.cells(1).pastespecial xlpastevalues, , false, false         '.cells(1).pastespecial xlpasteformats, , false, false         '.cells(1).select         application.cutcopymode = false         on error resume next         .drawingobjects.visible = true         .drawingobjects.delete         on error goto 0     end 

becase if made copy , paste dont lost format.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -