Hack 56 Reduce Document Bloat by Deleting Old List Templates![]() ![]() heavily edited can become needlessly bloated by the remnants of lists long since deleted from the text. This hack shows how to clean out this cruft.Every list you create in Word is based on an internally defined list template. These templates function like paragraph styles, allowing the properties of a list to be defined once, then referenced many times later on.But once it's been created, you can't remove a list template. Over time, a large document may accumulate hundreds, or even thousands, of these list templates. As you might imagine, that can have a negative impact on both the file's size and its stability.With Word 2003, the situation is greatly improved: Word caps the number of inactive list templates in a document at 50, automatically removing any old, unused templates once that threshold is met. However, many individuals and offices still use older versions of Word, which makes their documents susceptible to serious bloating issues from extraneous list templates.To see how quickly these list templates can accumulate, try the following:Open a new, blank Word document.With your cursor in the document, alternately click the Bullets button and the Numbering button a dozen or so times.Select Tools Alt-F11), type the following in the Immediate window [Hack #2], and press Enter: ?ActiveDocument.ListTemplates.CountVBA will report the number of list templates you created (see Figure 6-10). Notice that the number matches the number of times you clicked the Bullets and Numbering buttons. That's a lot of list templates for a blank document! Figure 6-10. Counting the number of list templates in a document![]() Word 2003 removes old lists when the number gets above 50. If you use an older version of Word, however, you can create a hack to help you clean out your list templates.As with [Hack #41], you can convert your document into a format such as RTF and delete anything you please. The RTF files put all the list templates in one place, and then use numbers to reference them in the document text. You can remove any list templates not referenced in the document without affecting the existing text.
6.7.1 The CodeThe following Perl script will clean out unused list templates from an RTF file. It uses the RTF::Parser module. If you're running the ActivePerl distribution for Windows, you can install RTF::Parser from the Perl Package Manager. You can also download the RTF::Parser from http://www.cpan.org. #!/usr/bin/perlSave the script as cleanlists.pl. 6.7.2 Running the HackAs described earlier, create a new, blank document and alternately click the Bullets and Numbering buttons a few dozen times. Use VBA to make sure that you soiled the file with extra list templates, as shown in Figure 6-10. Now save the file as RTF and name it DirtyFile.rtf.With the script in the same directory as the DirtyFile.rtf file, enter the following at a DOS command prompt: > perl cleanlists.pl DirtyFile.rtf > CleanFile.rtfOpen the new file, CleanFile.rtf, from Word. Once you're satisfied the script hasn't altered any existing formatting, you can save it in .doc format.
|