我的知识库中有4,000个记录,几乎全部以单词格式。许多人的格式为我们的预设样式,其中大约有20个。','样式b'到"新样式b"等。我可以做到这一点,但想问如何检查段落的当前样式名称是否是我们的20个预设样式之一。/div>
找到所选段落的样式名称,使用:
Selection.ParagraphFormat.Style.NameLocal ' or Name
要使用内置样式,使用:
ActiveDocument.Styles(wdStyleNormal)
使用wdStyleNormal
一个内置的单词常数,其中所有(大多数)标准样式都有许多。我可以使用样式名称来使用自己的(不是内置)样式来工作。查找Styles
在帮助方面有关详细信息。
以下宏我用来将(副本)样式从准备的模板分发到用户的普通模板:
Sub CopyStyles()
Dim n, src, dst
'
On Error Resume Next
src = ActiveDocument.AttachedTemplate.FullName
dst = NormalTemplate.FullName
'
' Copy styles
'
n = ActiveDocument.Styles(wdStyleNormal).ParagraphFormat.SpaceBefore
ActiveDocument.Styles(wdStyleNormal).ParagraphFormat.SpaceBefore = 0
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleNormal).NameLocal
ActiveDocument.Styles(wdStyleNormal).ParagraphFormat.SpaceBefore = n
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleHeading1).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleHeading2).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleHeading3).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleHeading4).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleHeading5).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleHeading6).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleTOC1).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleTOC2).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleTOC3).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleTOC4).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleTOC5).NameLocal
Application.OrganizerCopy Source:=src, Destination:=dst, Object:=wdOrganizerObjectStyles, Name:=ActiveDocument.Styles(wdStyleTOC6).NameLocal
End Sub
也许我理解您的问题错误。以下是一些示例,可能更多地朝着您寻找的方向:
Sub test()
Dim para As Paragraph
' rename a style of the document
'
On Error GoTo lbl_NoSuchStyle
ActiveDocument.Styles("TestStyle1").NameLocal = "TestStyle2"
On Error GoTo 0
lbl_NoSuchStyle:
'
' Check styles of all paragraphs
'
For Each para In ActiveDocument.Paragraphs
Select Case para.Format.Style.NameLocal
Case "Req"
Debug.Print "Isa Req"
Case "TestStyle2"
para.Style = wdStyleHeading3 ' change style to another style
Case Else
Debug.Print "Unknown Style"
End Select
Next para
End Sub