Consulting

Results 1 to 14 of 14

Thread: Locating font type ex. "Times New Roman"

  1. #1
    VBAX Regular
    Joined
    Oct 2006
    Posts
    10
    Location

    Exclamation Locating font type ex. "Times New Roman"

    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...

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Psyclops
    Welcome to VBAX.

    [vba]
    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

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Amended as requested.
    Thanks Gerry.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Wheeew...I was worried you may take that as intrusive.

  6. #6
    VBAX Regular
    Joined
    Oct 2006
    Posts
    10
    Location
    Thanks to all of you mdmackillkop and fumei for the quick response...
    I really appreciate your help and I'll try it now...

  7. #7
    VBAX Regular
    Joined
    Oct 2006
    Posts
    10
    Location
    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...


    [VBA]
    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
    [/VBA]

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Psyclops
    Try "Sentences" instead of "Words" (untested)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Oct 2006
    Posts
    10
    Location
    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...

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Why are you trying to do this?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    VBAX Regular
    Joined
    Oct 2006
    Posts
    10
    Location
    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....

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Hehehehehe.

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

  14. #14
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Happy to hand over to the Expert now!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •