Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get font info from Word Doc

Posted on 2004-10-26
5
Medium Priority
?
346 Views
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.

Thanks,
0
Comment
Question by:APlusComp247
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Expert Comment

by:SweatCoder
ID: 12417876
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
 
LVL 2

Expert Comment

by:koolnurd
ID: 12418535
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
 
LVL 10

Expert Comment

by:ADSaunders
ID: 12419228
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
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 2000 total points
ID: 12420152
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
 

Author Comment

by:APlusComp247
ID: 12429857
Thanks jimbobmcqee!!!!  It works great!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

609 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