Michael Seydl said:
I'm more looking for a kind of sdk because i'd like to create a add-in that
can intercept "open-document"-events and scan the document for particular
fonts. Optinal it should be also possible to replace fonts in certain areas
of text.
Easily done with VBA:
Create a new document with the code below and save it as a template.
Store the template in the Startup folder. Restart Word. Open a saved
document - the CheckFonts routine will be called by AutoNew, which is
triggered by the _DocumentChange event. Modify to suit.
Put this in a regular code module (Insert/Module):
Dim clsFontCheck As CDocChange
Public Sub AutoExec()
Set clsFontCheck = New CDocChange
Debug.Print "Test"
End Sub
Public Sub CheckFonts()
Const csFoundFonts As String = _
"Found these fonts: "
Dim st As Style
Dim vCheckFonts As Variant
Dim i As Long
Dim sFontsInUse As String
vCheckFonts = Array("Arial", "Times", "Lucida Grande")
For i = LBound(vCheckFonts) To UBound(vCheckFonts)
For Each st In ActiveDocument.Styles
If st.InUse Then
If st.Font.Name = vCheckFonts(i) Then
sFontsInUse = ", " & vCheckFonts(i)
Exit For
End If
End If
Next st
Next i
If Len(sFontsInUse) > 0 Then _
MsgBox csFoundFonts & Mid(sFontsInUse, 3)
End Sub
Put this in a new Class Module named CDocChange
Public WithEvents oApp As Application
Private Sub Class_Initialize()
Set oApp = Application
End Sub
Private Sub oApp_DocumentChange()
'Generic Document Change macro
Dim nOpenDocs As Long
Static nOldOpenDocs As Long
On Error GoTo ErrorHandler
nOpenDocs = oApp.Documents.Count
Select Case nOpenDocs - nOldOpenDocs
Case Is > 0
If oApp.ActiveDocument.Path = vbNullString Then
AutoNew
Else
AutoOpen
End If
Case Is < 0
AutoClose
Case Else
DocChangedFocus
End Select
nOldOpenDocs = nOpenDocs
ResumeHere:
Exit Sub
ErrorHandler:
Debug.Print "oApp_DocumentChange:", Err.Number, Err.Description
Resume ResumeHere
End Sub
Private Sub AutoNew()
End Sub
Private Sub AutoOpen()
CheckFonts
End Sub
Private Sub AutoClose()
End Sub
Private Sub DocChangedFocus()
End Sub