Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-2021, 05:28 AM
Matt C's Avatar
Matt C Matt C is offline Check the font attached to a template's "Normal" style and report if it's not installed Windows 10 Check the font attached to a template's "Normal" style and report if it's not installed Office 97-2003
Advanced Beginner
Check the font attached to a template's "Normal" style and report if it's not installed
 
Join Date: May 2021
Location: London, UK
Posts: 30
Matt C is on a distinguished road
Question Check the font attached to a template's "Normal" style and report if it's not installed

Hi folks.

I found this useful code on Adam Dimech's Coding Blog which checks to see if the User has the required template font installed on their computer and reports with a Message Box.

However, I'd like VBA to check for whatever font has been set in the "Normal" style when creating a new, or opening an existing, document based on the template, rather than specifying a font name in the code.

Quote:
Sub FontCheck()
'
' With thanks to Adam Dimech's Coding Blog (Adam Dimech's Coding Blog)
'


Dim lFound As Boolean
Dim font As Variant

font = "Courier Final Draft" 'This is where I'd like it to check the "Normal" style font
Let lFound = False

For Each aFont In Application.FontNames
If aFont = font Then
Let lFound = True
End If

Next aFont

If lFound = False Then
Call MsgBox("Please install the font '" & font & "' before using this template.", vbExclamation, "Required font missing")
End If
End Sub
Thanks in advance, folks.
Reply With Quote
  #2  
Old 06-06-2021, 05:44 AM
Guessed's Avatar
Guessed Guessed is offline Check the font attached to a template's "Normal" style and report if it's not installed Windows 10 Check the font attached to a template's "Normal" style and report if it's not installed Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

ActiveDocument.Styles(wdStyleNormal).Font.Name
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 06-06-2021, 03:50 PM
macropod's Avatar
macropod macropod is offline Check the font attached to a template's "Normal" style and report if it's not installed Windows 10 Check the font attached to a template's "Normal" style and report if it's not installed Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You might also be interested in:

Code:
Sub ListInstalledFonts()
Application.ScreenUpdating = False
Dim ListFont As Variant
With ActiveDocument.Characters
  For Each ListFont In FontNames
    With .Last
      .Font.Name = "Arial"
      .Font.Size = 12
      .Text = ListFont & Chr(11)
    End With
    With .Last
      .Font.Name = ListFont
      .InsertAfter "ABCDEFGHIJKLMNOPQRSTUVWXYZ ~!@#$%^&*()_+|<>?:{}" & Chr(11) & _
        "abcdefghijklmnopqrstuvwxyz `1234567890-=\,.;'[]" & vbCr
    End With
    With .Last
      .Font.Name = "Arial"
      .InsertAfter vbCr
    End With
  Next ListFont
End With
Application.ScreenUpdating = True
End Sub
and:
Code:
Sub TestDocFonts()
Application.ScreenUpdating = False
Dim StrFnt As Variant, StrFnts As String, StrInFnt As String, StrNoFnt As String, Fnt As Font
For Each StrFnt In FontNames
  StrFnts = StrFnts & "'" & StrFnt
Next
StrFnts = StrFnts & "'"
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Format = True
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Text = "[!^13]{1,}"
    With .Replacement
      .ClearFormatting
      .Text = "^&"
      .Font.Hidden = True
    End With
    .Execute Replace:=wdReplaceAll
    .Text = "?"
    .Font.Hidden = True
    .Execute
  End With
  Do While .Find.Found
    Set Fnt = .Font
    With Fnt
      If InStr(StrFnts, "'" & .Name & "'") > 0 Then
        StrInFnt = StrInFnt & vbCr & .Name
      Else
        StrNoFnt = StrNoFnt & vbCr & .Name
      End If
    End With
    With .Duplicate.Find
      .Font.Hidden = True
      .Replacement.Font.Hidden = False
      .Font.Name = Fnt.Name
      .Execute Replace:=wdReplaceAll
      .Font.Name = Fnt.Name & Fnt.NameAscii
      .Execute Replace:=wdReplaceAll
      .Font.Name = ""
      .Font.NameAscii = Fnt.NameAscii
      .Execute Replace:=wdReplaceAll
    End With
    .Find.Execute
    DoEvents
  Loop
End With
Application.ScreenUpdating = True
MsgBox "The following fonts were found in the document, and on the system:" & StrInFnt
MsgBox "The following fonts were found in the document, but not on the system:" & StrNoFnt
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 10-31-2021, 05:54 AM
Matt C's Avatar
Matt C Matt C is offline Check the font attached to a template's &quot;Normal&quot; style and report if it's not installed Windows 10 Check the font attached to a template's &quot;Normal&quot; style and report if it's not installed Office 97-2003
Advanced Beginner
Check the font attached to a template's &quot;Normal&quot; style and report if it's not installed
 
Join Date: May 2021
Location: London, UK
Posts: 30
Matt C is on a distinguished road
Default

Firstly, huge apologies to Andrew and Paul for not thanking them for the replies. Work got the better of me and I missed the reply notifications. The above is useful, many thanks.

I'd like to take it a step further for another area of the VBA. To illustrate, please see the adapted code below with commenting.

Quote:
Sub FontCheckAndSubstitute()
'
' Check for "Blobby" font and apply it to "Normal" style.
' If "Blobby" font is not installed, substitute with something from a set list of alternatives.
' If alternatives are not installed, let Word substitute with nearest common font
'
Dim lFound As Boolean
Dim font As Variant

font = "Blobby"
Let lFound = False

' Check for "Blobby" font

For Each aFont In Application.FontNames
If aFont = font Then
Let lFound = True
End If

Next aFont

' If "Blobby" font isn't installed...

If lFound = False Then
Call MsgBox("For best results, please install the font '" & font & "'. Word will substitute with the closest match." & vbCrLf & vbCrLf & _
"Pres OK to continue.", vbOKOnly + vbExclamation, "Required Font Missing")

' Need help here:

' Substitute "Blobby" with a font from a list of alternatives (e.g. "Jelly", "Spongey", "Bouncey")
' Or let Word substitute with a common font if alternatives are not installed (e.g. "Courier New")

End If


' Apply "Blobby" or substituted font to Normal style

With ActiveDocument.Styles("Normal").font
.Name = font '<------ Is this correct?
.Size = 12
End With

End Sub
Thanks, folks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Changes have been made that affect the global template, Normal.dotm. ..." DBlomgren Word 11 12-18-2017 12:54 PM
Setting Font Color and Style "permanently" wings1080 Word 5 12-19-2014 08:44 AM
Check the font attached to a template's &quot;Normal&quot; style and report if it's not installed Documents hung up, Word won't close due to "Changes made..to global template Normal.dotm" pagskg Word 2 07-23-2014 12:54 PM
Style doesn't enforce "Do not check spelling" Jennifer Murphy Word 7 01-30-2012 12:51 AM
Check the font attached to a template's &quot;Normal&quot; style and report if it's not installed "Table of content" based on "Normal Style" behavior!!!! Jamal NUMAN Word 4 07-08-2011 04:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft