vba - Excel Macro / Module assistance - How to write a code to autofit Cell width -
i got module/macro excel form site: [macro send email of excel content][1] macro works, except cells small large amount of data in each cell, how write script within code adjust width of cell accordingly data inside cell. cells vary in terms of amount of data. thanks!
sub send_row() ' don't forget copy function rangetohtml in module. ' working in office 2000-2010 dim outapp object dim outmail object dim cell range dim rng range dim ash worksheet set ash = activesheet on error goto cleanup set outapp = createobject("outlook.application") application .enableevents = false .screenupdating = false end each cell in ash.columns("b").cells.specialcells(xlcelltypeconstants) if cell.value "?*@?*.?*" , lcase(cell.offset(0, 1).value) = "yes" ash.range("a1:ae100").autofilter field:=2, criteria1:=cell.value ash.autofilter.range on error resume next set rng = .specialcells(xlcelltypevisible) on error goto 0 end set outmail = outapp.createitem(0) on error resume next outmail .to = cell.value .subject = "csi" .htmlbody = rangetohtml(rng) .display 'or use send end on error goto 0 set outmail = nothing ash.autofiltermode = false end if next cell cleanup: set outapp = nothing application .enableevents = true .screenupdating = true end end sub
i use
excel.rows.autofit
and
excel.columns.autofit
to make worksheet cells automatically adjust best height , width content.
you can call these 2 lines of code anywhere in code, before creating email.
as alternative, if wanted manually, use these shortcut keys:
alt+o+c+a - autofit columns
alt+o+r+a - autofit rows
Comments
Post a Comment