vba - Formating all tables in file with style -
i'm working kind of documentation @ moment, consists of lots , lots of tables. , may have guessed now, need format them style. so, there's vba macro exclusively made purpose - creates required style , applies tables in file. seems problem when i'm working large document. so, let's see working code, ommiting part, style created:
dim otable table each otable in activedocument.tables otable.select selection.tables(1).applystyledirectformatting ("foostyle") selection.tables(1).autofitbehavior (wdautofitfixed) selection.tables(1).applystylerowbands = true selection.tables(1).borders .insidelinestyle = wdlinestylesingle .insidelinewidth = wdlinewidth025pt .outsidelinestyle = wdlinestylesingle .outsidelinewidth = wdlinewidth025pt end 'make list last row of table selection.tables(1).cell(row:=8, column:=1).range.select selection.range.listformat.applylisttemplate listtemplate:=listgalleries(wdoutlinenumbergallery).listtemplates(2) next
so code works nicely documents less 600 pages. otherwise stops @ line
.insidelinestyle = wdlinestylesingle
with run-time error 4605 telling stories memory , disk space. i've done research , found this awesome thread telling downsides of selection. following given advice , changed macro's code bit, resulting in following:
dim ltbl long ltbl = 1 activedocument.tables.count activedocument.tables(ltbl).applystyledirectformatting ("barstyle") activedocument.tables(ltbl).autofitbehavior (wdautofitfixed) activedocument.tables(ltbl).applystylerowbands = true activedocument.tables(ltbl).borders .insidelinestyle = wdlinestylesingle .insidelinewidth = wdlinewidth025pt .outsidelinestyle = wdlinestylesingle .outsidelinewidth = wdlinewidth025pt end 'make list last row of table activedocument.tables(ltbl).cell(row:=8, column:=1).range.listformat.applylisttemplate listtemplate:=listgalleries(wdoutlinenumbergallery).listtemplates(2) next
yeah, creepily long line. nope, nothing changed. seems there're no more selections, still same error @ same place. tried changing part debugger stopped when error appeared:
for each ocell in activedocument.tables(ltbl).range.cells ocell.borders.outsidelinestyle = wdlinestylesingle ocell.borders.outsidelinewidth = wdlinewidth025pt next
to no avail - still got same problem. @ point decided experiments , removed next last line of code (that long-a** line)... , voila - macro works charm, no errors, no complaints, nothing. arguments sake tried making same changes first version of macro , results same - seems line's fault along. leaving not solution, numbered list in last row must. then, should macro doesn't pop error?
that kind of problem can solved splitting task 2 loops. first iteration change table formatting. second iteration add listformat
expected.
of course, result slower subroutine need.
Comments
Post a Comment