Prev: Combine Multiple Documents
Next: Preserve the initial scope of a selection on a search operation and re-use it later
From: Harry Hondalf on 28 Feb 2010 11:03 The VBA scripts that I have found all implement a character-by-character scan through the document, which can take a long time in later versions of Word. You can blame Word's "formatting" feature for the slowdown. Thereâs a faster way: Save the document in .rtf format, then open the .rtf file in a text editor such as notepad.exe. The fonts are listed in a font table ( {\fonttbl ) located at the very beginning of the file. Each font entry looks something like this: {\f0\froman\fprq2\fcharset0 Times New Roman;} Any entries with a character set other than \fcharset0 can be ignored. (To make it easier to read the temporary rtf file, search for "{" and replace with "<newline>{", where <newline> means CRLF in Windows, or CR in linux. I dunno what it is in Mac.) Word, of course, doesnât follow Micro$oftâs own RTF specification exactly, so sometimes there will be extra tokens (text embedded between braces) within the font token. I wrote a VBA macro that extracts the font names. I'll post the macro here (or email it) if anybody's interested. -sadhu! url:http://www.ureader.com/gp/1022-1.aspx
From: Yves Dhondt on 28 Feb 2010 12:24
There is a reason to do a character by character scan: your method will also return template fonts which might not be in use in the text but are still part of the document. On a side note, assuming Word 2007, in VBA you can just use the OpenXML method and query that for the w:fonts element which contains a list of w:font elements which are the same as what your 'fcharset0' collection will return. This way, you won't have to save to an external file and parse that one. Yves "Harry Hondalf" <mald_guy_44(a)yahoo.co.in> wrote in message news:f82e81c7e248446da180208241e1b713(a)newspe.com... The VBA scripts that I have found all implement a character-by-character scan through the document, which can take a long time in later versions of Word. You can blame Word's "formatting" feature for the slowdown. There's a faster way: Save the document in .rtf format, then open the .rtf file in a text editor such as notepad.exe. The fonts are listed in a font table ( {\fonttbl ) located at the very beginning of the file. Each font entry looks something like this: {\f0\froman\fprq2\fcharset0 Times New Roman;} Any entries with a character set other than \fcharset0 can be ignored. (To make it easier to read the temporary rtf file, search for "{" and replace with "<newline>{", where <newline> means CRLF in Windows, or CR in linux. I dunno what it is in Mac.) Word, of course, doesn't follow Micro$oft's own RTF specification exactly, so sometimes there will be extra tokens (text embedded between braces) within the font token. I wrote a VBA macro that extracts the font names. I'll post the macro here (or email it) if anybody's interested. -sadhu! url:http://www.ureader.com/gp/1022-1.aspx |