PDA

View Full Version : Locating font type ex. "Times New Roman"



Psyclops
10-10-2006, 06:18 AM
Anybody,

I want to test a word document if its font is "Times New Roman"
if not I want to highlight those word/sentences that is not in Times new Roman...

Is this possible using Macro?

Thanks in advance...

mdmackillop
10-10-2006, 09:45 AM
Hi Psyclops
Welcome to VBAX.


Option Explicit
Sub HighlightNonFont()
Dim w As Object
For Each w In ActiveDocument.Words
If w.Font.Name <> "Times New Roman" Then
w.HighlightColorIndex = wdRed
End If
Next
End Sub

fumei
10-10-2006, 12:24 PM
Hi Malcom. If I may gently suggest...for newbies it would be better to put put full code (and...ahem...Option Explicit) in your posts. Just plunking that code into a procedure will not do much....I know....I just tried.

mdmackillop
10-10-2006, 03:15 PM
Amended as requested.
Thanks Gerry.

fumei
10-10-2006, 06:20 PM
Wheeew...I was worried you may take that as intrusive.

Psyclops
10-10-2006, 07:44 PM
Thanks to all of you mdmackillkop and fumei for the quick response...
I really appreciate your help and I'll try it now...

Psyclops
10-10-2006, 08:03 PM
Hi ,

Just a follow-up

Do you think in this code whitespaces are also included to be highlight if its font is not in times new roman...

Thanks again...



Option Explicit

Sub HighlightNonFont()

Dim w As Object

For Each w In ActiveDocument.Words
If w.Font.Name <> "Times New Roman" Then
w.HighlightColorIndex = wdRed
End If
Next

End Sub

mdmackillop
10-11-2006, 12:02 AM
Hi Psyclops
Try "Sentences" instead of "Words" (untested)

Psyclops
10-11-2006, 12:37 AM
Hi MD,

I have tried using "Sentences" instead of "Words" and the results is almost the same...

I think the problem is the whitespaces inside the table...Is there any possible solutions to this...

mdmackillop
10-11-2006, 12:44 AM
Why are you trying to do this?

Psyclops
10-11-2006, 02:06 AM
Hi MD,

I want to automatically verify if a set of documents is correct based on specified format before uploading it as HTML because sometimes when it is
uploaded as HTML file some of properties have been change if you pre-format.

I'm trying to check those font used in the entire document and if not i should highlight those fonts but when a font is inside the table, a whitespace, and not in Times New Roman it cannot highlight this portion....

mdmackillop
10-11-2006, 03:28 AM
Can you not simply select the table and apply TNR to the whole of the text.
If you're using mixed fonts, you should consider using styles, but that's another story!

fumei
10-11-2006, 04:41 AM
Hehehehehe.

Hmmmmmmmmmmmmm..........Styles? Whataconcept.

mdmackillop
10-11-2006, 04:46 AM
Happy to hand over to the Expert now! :rotlaugh: