Get font info from Word Doc

Posted on 2004-10-26
Last Modified: 2013-12-03
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.

Question by:APlusComp247
    LVL 11

    Expert Comment

    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:
    LVL 2

    Expert Comment

    try it , after opening the document . 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
    LVL 10

    Expert Comment

    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
    LVL 16

    Accepted Solution

    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






    Author Comment

    Thanks jimbobmcqee!!!!  It works great!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now