新建宏php
Sub a() Dim str As String For Each c In ThisDocument.Characters If InStr(str, c.Font.Name) = 0 And Len(c.Font.Name) > 0 Then str = str & c.Font.Name & "," End If Next MsgBox UBound(Split(Left(str, Len(str) - 1), ",")) + 1 & "種字體,分別是" & vbCrLf & Left(str, Len(str) - 1) End Sub
再運行宏html
Reports all fonts used in a file, then which fonts are not present on the PC. express
You receive files from others, and they often use fonts you don't have, but you're not sure, without carefully looking through the entire file, which fonts have been used. Using this code lets you check to make sure you're seeing what you're supposed to be seeing in the document. Particularly nice for desktop publishing tasks.字體
Option Explicit Public Sub Main() Dim sMsg As String sMsg = GetFonts(ActiveDocument) MsgBox "The fonts in this document are:" & vbNewLine & vbNewLine & sMsg If Not CompareFonts(sMsg) = vbNullString Then MsgBox "The following fonts are used in this document," & _ vbNewLine & "but are not installed on this PC:" & vbNewLine & CompareFonts(sMsg) End If End Sub Private Function GetFonts(ByVal oDocument As Document) As String Dim oParagraph As Paragraph Dim i As Integer Dim oWord As Words Dim sFontType As String Dim sMsg As String For Each oParagraph In oDocument.Paragraphs For i = 1 To oParagraph.Range.Characters.Count sFontType = oParagraph.Range.Characters(i).Font.Name If InStr(1, sMsg, sFontType) = 0 Then sMsg = sMsg & sFontType & vbNewLine End If Next Next GetFonts = sMsg End Function Private Function CompareFonts(ByVal oFonts As String) As String Dim vFont As Variant Dim sMsg As String Dim xFont As Variant Dim i As Long Dim allFonts As String For Each vFont In FontNames allFonts = allFonts & vbNewLine & vFont Next vFont xFont = Split(oFonts, vbNewLine) For i = 0 To UBound(xFont) If InStr(allFonts, xFont(i)) = 0 Then sMsg = sMsg & vbNewLine & xFont(i) End If Next i CompareFonts = sMsg End Function
https://word.tips.net/T011069...this