List of fonts used in a Word doc -- the easy way

H

Harry Hondalf

The VBA scripts that I have found all implement a character-by-character scan throu=
gh the document, which can take a long time in later versions of Word. You can blame Wor=
d's "formatting" feature for the slowdown.

There=E2=80=99s a faster way: Save the document in .rtf format, then open the .rtf fi=
le in a text editor such as notepad.exe. The fonts are listed in a font table ( {\fonttb=
l ) located at the very beginning of the file. Each font entry looks something like thi=
s: =


{\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 "<ne=
wline>{", where <newline> means CRLF in Windows, or CR in linux. I dunno what it is in M=
ac.)

Word, of course, doesn=E2=80=99t follow Micro$oft=E2=80=99s own RTF specificati=
on exactly, so sometimes there will be extra tokens (text embedded between braces) w=
ithin 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
 
Y

Yves Dhondt

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top