Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

摘要

本文包含 Visual Basic for Applications 產生一份到 Microsoft Word 中可用的字型的巨集,並顯示每個字型的範例。

這些巨集所產生的字型清單取決於在 [列印] 對話方塊中選取的印表機。

更多的資訊

Microsoft 會提供程式設計範例僅供說明,而不做任何明示或默示的保證。這包括,但不限於適售性或適合某特定用途之默示擔保責任。本文假設您已相當熟悉使用的我們所示範的程式設計語言以及建立和偵錯程序所使用的工具。Microsoft 技術支援工程師可以協助解釋特定程序中,功能,但它們不會修改這些範例以提供附加功能或建構程序來滿足您特定需求。
下列範例 Visual Basic for Applications 巨集建立新的空白文件,並將插入每個可用的字型的範例:

Sub ListFonts()

Dim varFont As Variant
' Speeds macro processing and suppresses display.
Application.ScreenUpdating = False
' Create new document.
Documents.Add Template:="normal"

' Loop through each available font.
For Each varFont In FontNames
With Selection
' Format for name of font.
.Font.Name = "times new roman"
.Font.Bold = True
.Font.Underline = True
' Insert Font name.
.TypeText varFont
' Insert a new paragraph after the Font Name.
.InsertParagraphAfter
' Move to the new paragraph.
.MoveDown unit:=wdParagraph, Count:=1, Extend:=wdMove
' Format for the font example.
.Font.Bold = False
.Font.Underline = False
.Font.Name = varFont
' Enter example text(Alphabetic characters.)
.TypeText "abcdefghijklmnopqrstuvwxyz"
' Insert a new paragraph.
.InsertParagraphAfter
' Move to the new paragraph.
.MoveDown unit:=wdParagraph, Count:=1, Extend:=wdMove
' Insert example text(Numeric characters.)
.TypeText "0123456789?$%&()[]*_-=+/<>"
' Insert two new paragraphs and move down.
.InsertParagraphAfter
.InsertParagraphAfter
.MoveDown unit:=wdParagraph, Count:=1, Extend:=wdMove
End With

Next varFont
Application.ScreenUpdating = True

End Sub


下列巨集會建立新的空白文件、 建立一個表格中,然後插入每個可用的字型的範例:

Sub ListAllFonts()

Dim J As Integer
Dim FontTable As Table
'Start off with a new document
Set NewDoc = Documents.Add
'Add a table and set the table header
Set FontTable = NewDoc.Tables.Add(Selection.Range, FontNames.Count + 1, 2)
With FontTable
.Borders.Enable = False
.Cell(1, 1).Range.Font.Name = "Arial"
.Cell(1, 1).Range.Font.Bold = 1
.Cell(1, 1).Range.InsertAfter "Font Name"
.Cell(1, 2).Range.Font.Name = "Arial"
.Cell(1, 2).Range.Font.Bold = 1
.Cell(1, 2).Range.InsertAfter "Font Example"
End With
'Go through all the fonts and add them to the table
For J = 1 To FontNames.Count
With FontTable
.Cell(J + 1, 1).Range.Font.Name = "Arial"
.Cell(J + 1, 1).Range.Font.Size = 10
.Cell(J + 1, 1).Range.InsertAfter FontNames(J)
.Cell(J + 1, 2).Range.Font.Name = FontNames(J)
.Cell(J + 1, 2).Range.Font.Size = 10
.Cell(J + 1, 2).Range.InsertAfter "ABCDEFG abcdefg 1234567890"
End With
Next J
FontTable.Sort SortOrder:=wdSortOrderAscending
End Sub

如需有關如何使用本文中的範例程式碼的詳細資訊,請按一下下面的文件編號,檢視 「 Microsoft 知識庫 」 中的文件:

212536如何從 Office 2000 中的知識庫文件中執行範例程式碼

參考

如其他有關如何取得說明與 Visual Basic for Applications 的詳細資訊,請按一下下面的文件編號,檢視 「 Microsoft 知識庫 」 中的文件:

程式設計資源的212623巨集

226118的資源清單了可幫助您了解程式設計的 Visual Basic for Applications

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×