html - How to align RangetoHTML code by Ron de Bruin? -
i'm working on left alignment of copied excel cells on outlook using vba. unluckily, whenever run program, excel cells copied on center alignment. need align in left form.
function rangetohtml(rng range) ' changed ron de bruin 28-oct-2006 ' working in office 2000-2016 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 .cells(1).pastespecial xlpastevalues, , false, false .cells(1).pastespecial xlpasteformats, , false, false tempwb.sheets(1).usedrange.rows.autofit .cells(1).select 'cells(1).entirerow.autofit 'cells(1).entirecolumn.autofit 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=left 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
i've tried html styling codes none works.
Comments
Post a Comment