vba - Having an issue with renumbering list items, MOSTLY works -
we have 3rd party application that: 1) locates data in various dbs, 2) writes .docm file, based on blank .dotm, , 3) runs parent sub routine newly created .docm.
when other app creates word file, , creating list of stuff, creates separate list each item in list. example:
- stuff no. 1
- --> stuff no. 1.1
- stuff no. 2
- stuff no. 3
- stuff no. 4
each of items different list block (5 lists together). when creating lists in word, list 1 block. well, know, can't change fact other application. i'm flat stuck , know have no other alternative. so...
- i have word file has 9 different styles, exclusive list items. using advantage. (list_paragraph1, list_paragraph2, ..., list_paragraph9)
i need cycle through document, , replace list indices (just number, letter, or roman numeral) indent spacing, "paragraphs" use 1 of 9 styles. code follows:
sub reconfigurelistindices() call locatelistitems(activedocument) end sub private function locatelistitems(thisdocument word.document) dim integer dim mystyles(0 10) string dim para paragraph dim indexvalue_level long dim indexvalue_level1 long dim indexvalue_level2 long dim indexvalue_level3 long dim indexvalue_level4 long dim indexvalue_level5 long dim indexvalue_level6 long dim indexvalue_level7 long dim indexvalue_level8 long dim indexvalue_level9 long dim stylematchesliststyle boolean mystyles(0) = "list_paragraph1" mystyles(1) = "list_paragraph2" mystyles(2) = "list_paragraph3" mystyles(3) = "list_paragraph4" mystyles(4) = "list_paragraph5" mystyles(5) = "list_paragraph6" mystyles(6) = "list_paragraph7" mystyles(7) = "list_paragraph8" mystyles(8) = "list_paragraph9" 'initialize values indexvalue_level1 = 1 indexvalue_level2 = 1 indexvalue_level3 = 1 indexvalue_level4 = 1 indexvalue_level5 = 1 indexvalue_level6 = 1 indexvalue_level7 = 1 indexvalue_level8 = 1 indexvalue_level9 = 1 'loop through paragraphs in document each para in thisdocument.paragraphs 'initialize boolean later processing if instr(1, ucase(para.style), ucase(left(mystyles(1), len(mystyles(1)) - 1)), vbtextcompare) > 0 stylematchesliststyle = false 'loop through list of styles using in document = lbound(mystyles) ubound(mystyles) if instr(1, para.range.text, "questionable", vbtextcompare) > 0 stop end if if para.style = mystyles(a) 'msgbox para.range.listformat.listlevelnumber 'the current item has been identified list item, increment ' index of appropriate level select case case 0 indexvalue_level1 = indexvalue_level1 + 1 indexvalue_level2 = 0 indexvalue_level3 = 0 indexvalue_level4 = 0 indexvalue_level5 = 0 indexvalue_level6 = 0 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level1 case 1 indexvalue_level2 = indexvalue_level2 + 1 indexvalue_level3 = 0 indexvalue_level4 = 0 indexvalue_level5 = 0 indexvalue_level6 = 0 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level2 case 2 indexvalue_level3 = indexvalue_level3 + 1 indexvalue_level4 = 0 indexvalue_level5 = 0 indexvalue_level6 = 0 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level3 case 3 indexvalue_level4 = indexvalue_level4 + 1 indexvalue_level5 = 0 indexvalue_level6 = 0 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level4 case 4 indexvalue_level5 = indexvalue_level5 + 1 indexvalue_level6 = 0 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level5 case 5 indexvalue_level6 = indexvalue_level6 + 1 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level6 case 6 indexvalue_level7 = indexvalue_level7 + 1 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level7 case 7 indexvalue_level8 = indexvalue_level8 + 1 indexvalue_level9 = 0 indexvalue_level = indexvalue_level8 case 8 indexvalue_level9 = indexvalue_level9 + 1 indexvalue_level = indexvalue_level9 case else = 1 indexvalue_level1 = indexvalue_level1 + 1 indexvalue_level2 = 0 indexvalue_level3 = 0 indexvalue_level4 = 0 indexvalue_level5 = 0 indexvalue_level6 = 0 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 indexvalue_level = indexvalue_level1 end select 'now know indent level, , index value want, set call reformatliststyle(para.range.listformat, + 1, indexvalue_level) 'set flag keep index values, break out of loop stylematchesliststyle = true exit end if next if stylematchesliststyle = false 'looks current paragraph isn't list item, reset index values indexvalue_level1 = 0 indexvalue_level2 = 0 indexvalue_level3 = 0 indexvalue_level4 = 0 indexvalue_level5 = 0 indexvalue_level6 = 0 indexvalue_level7 = 0 indexvalue_level8 = 0 indexvalue_level9 = 0 end if end if next end function private function reformatliststyle(lstfrmt word.listformat, indentlevel integer, indexlevel long) dim list_numberformat string ' following need referenced in pixel format. ' use numbertopoints(#) convert pixels inches. dim list_numberposition integer dim list_numberstyle integer dim list_textposition integer dim list_tabposition integer dim list_stylearabic integer dim list_stylelroman integer dim list_styleuletter integer dim list_stylelletter integer dim list_stylearabicfullwidth integer dim list_stylenumcircle integer dim list_stylenone integer dim list_stylepicbullet integer dim list_stylebullet integer 'list out available style types project (mostly later reference) list_stylearabic = wdcaptionnumberstylearabic 'ex. "1" --> 0 list_stylelroman = wdlistnumberstylelowercaseroman 'ex. "i" --> 2 list_styleuletter = wdlistnumberstyleuppercaseletter 'ex. "a" --> 3 list_stylelletter = wdlistnumberstylelowercaseletter 'ex. "a" --> 4 list_stylearabicfullwidth = wdcaptionnumberstylearabicfullwidth 'ex. "??" --> 14 list_stylenumcircle = wdcaptionnumberstylenumberincircle 'ex. "??" --> 18 list_stylebullet = wdlistnumberstylebullet 'ex. "*" --> 23 list_stylepicbullet = wdlistnumberstylepicturebullet 'ex. "*" --> 249 list_stylenone = wdlistnumberstylenone 'ex. " " --> 255 'set left-to-right location of text if indentlevel > 9 list_numberposition = 36 else list_numberposition = indentlevel * 36 end if list_textposition = list_numberposition + 36 list_tabposition = list_textposition 'set list index format select case indentlevel case 1, 2, 3 list_numberformat = "%1)" case 4, 5, 6 list_numberformat = "%(1)" case 7, 8, 9 list_numberformat = "%1." case else list_numberformat = "%1)" end select 'set list index style select case indentlevel case 1, 4, 7 list_numberstyle = list_stylearabic case 2, 5, 8 list_numberstyle = list_stylelletter case 3, 6, 9 list_numberstyle = list_stylelroman case else list_numberstyle = list_stylearabic end select 'reformat listgallery listgalleries(wdoutlinenumbergallery).listtemplates(1).listlevels(1) .numberformat = list_numberformat .numberstyle = list_numberstyle .numberposition = list_numberposition .alignment = wdlistlevelalignleft 'unchanged .textposition = list_textposition .tabposition = list_tabposition .startat = indexlevel '.trailingcharacter = wdtrailingtab 'unchanged .resetonhigher = 0 'unchanged '.linkedstyle = "" 'unchanged end 'assign listgallery selection call lstfrmt.applylisttemplatewithlevel(listgalleries(wdoutlinenumbergallery).listtemplates(1), false, wdlistapplytoselection, wdword10listbehavior) end function when code runs, works. list indices increment correctly, format correctly, except indent levels 4, 5, , 6. actually, indent level 4 right, 5 , 6 appear duplicates of 4 , can't figure out why. spacing, numbering, , style...all same. have ideas?
thank time in advance!
Comments
Post a Comment