Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to detect all fonts and sizes in document (Word) 1

Status
Not open for further replies.

Bummy

Technical User
Feb 3, 2005
1
US
I'd like to write a macro that will display all of the fonts and font sizes used within a document. I've found the easy way of displaying the information for selected text:

Code:
MsgBox Selection.Font.Name & Selection.Font.Size

I would like to search the entire document and report all fonts and font sizes to the message box.

Any help will be appreciated.
 
#1 If you are searching for fonts and font sizes through a document, I am willing to bet that you are not using Styles. bad bad bad.

#2. A message box may not be the best display if you want a paragraph by paragraph statement of font, and size. With a large document, this could overflow the messagebox. The following creates a new document with the Font, and Font Size listed for every paragraph in the parsed document. You COULD have this display to a message box, but...as mentioned this is not a great idea for long dicument.

#3. What are you trying to do??

Code:
Sub FontAndSize()
Dim aPara As Paragraph
Dim msg As String
Dim paraCount As String
paraCount = ActiveDocument.Range.ComputeStatistics(wdStatisticParagraphs)
For Each aPara In ActiveDocument.Paragraphs()
    msg = msg & aPara.Range.Font.Name & "  " & aPara.Range.Font.Size & vbCrLf
Next
msg = "Total paragraphs = " & paraCount & vbCrLf & msg
Application.Documents.Add
Selection.TypeText Text:=msg
End Sub



Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top