以下是一个示例代码,可以读取当前活动文档的格式并输出各项格式的值:
Sub GetActiveDocumentFormat()
Dim doc As Document
Set doc = ActiveDocument
'获取文字样式
Debug.Print "字体名称:" & doc.Styles(doc.Range.Font.Style).NameLocal
Debug.Print "字体大小:" & doc.Range.Font.Size
Debug.Print "字体颜色:" & doc.Range.Font.ColorIndex
Debug.Print "加粗:" & doc.Range.Font.Bold
Debug.Print "倾斜:" & doc.Range.Font.Italic
Debug.Print "下划线:" & doc.Range.Font.Underline
Debug.Print "删除线:" & doc.Range.Font.StrikeThrough
'获取段落样式
Debug.Print "对齐方式:" & doc.Range.Paragraphs.Alignment
Debug.Print "行距:" & doc.Range.Paragraphs.LineSpacing
Debug.Print "首行缩进:" & doc.Range.Paragraphs.FirstLineIndent
Debug.Print "段前间距:" & doc.Range.Paragraphs.SpaceBefore
Debug.Print "段后间距:" & doc.Range.Paragraphs.SpaceAfter
End Sub
注意:此代码仅适用于Microsoft Word。如果您需要在其他应用程序中读取格式,请使用该应用程序的API。