[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Get font info from Word Doc

Can I open a Word Doc in VB and get the font name, size, and color for a single word in the document?

I have been doing a lot of searching and I have only found how to change the color of a word, but not identify it.  I also haven't found ANY good support for the Word Object Library, so if you have any good links that would be great.

Thanks,
0
APlusComp247
Asked:
APlusComp247
1 Solution
 
SweatCoderCommented:
not sure if this is exactly what you're looking for, but it may help:

========================================
Dim objWord As Word.Application
Set objWord = New Word.Application
With objWord.Selection.Find
            .Text = "<SoftwareID>"
            .Replacement.Text = Replace(Replace(Trim(SoftwareIDArray(LoopWord)), "0", "#"), "O", "@")
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
End With
objWord.Selection.Find.Execute Replace:=wdReplaceAll
========================================

and try this reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrmicrosoftword2000.asp
0
 
koolnurdCommented:
try it , after opening the document .

.Content.Fone.name returms the font name.


Dim strFile As String
 Dim appWord As New Word.Application
 Dim docWord As Word.Document
 
 Set docWord = appWord.Documents.Open("File Name with Path", False)
 Text1.Text = docWord.Content.Font.Name
0
 
ADSaundersCommented:
Hi APlusComp247,
Your best reference to the Word object library is the MSWord help file. Open the contents tab, and look near the bottom under 'Programming Information'. Under 'Getting Started with Microsoft Word Visual Basic' you will find a chapter on 'Working with Word Objects'

Regards .. Alan
0
 
jimbobmcgeeCommented:
You can do it by word, or by character (in case a word has more than one font, for some reason).  If you know which word in the active document you want to check (e.g. the 3rd word), you can use:

           strFontName = ActiveDocument.Words.Item(3).Font.Name
           intFontSize = ActiveDocument.Words.Item(3).Font.Size
           lngFontCol = ActiveDocument.Words.Item(3).Font.Color
           intFontColI = ActiveDocument.Words.Item(3).Font.ColorIndex

If you want the 3rd character, substitute

           ActiveDocument.Words.Item(3).Font.Name

with

           ActiveDocument.Characters.Item(3).Font.Name

HTH

J.
0
 
APlusComp247Author Commented:
Thanks jimbobmcqee!!!!  It works great!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now