检查文档中是否出现特定样式对于单个段落文档是否失败。 [英] Check if particular style appears in the document fails for a single paragraph document.
问题描述
我试图找到文档是否包含样式为"标题1"的任何文本。使用以下代码几乎适用于所有情况:
I am trying to find if the document contains any text with style "heading 1". Using the below code works for almost all cases:
Dim range
As Range = doc.Content
   
使用 range.Find
.Style = doc.Styles( " Heading
1" )。NameLocal
End
使用
返回(range.Find.Execute())
结束函数
推荐答案
您好
Prem-,
尝试使用下面的代码。它也适用于单个段落而无需输入段落。
try to use the code below. it can work for a single paragraph too without entering a paragraph break.
也能够找到并循环遍历所有"标题1"。文件中的段落。
also able to find and loop through all the "Heading 1" paragraphs in document.
Sub demo3()
Dim txt As String
Dim p As Paragraph
With ActiveDocument
For Each p In .Paragraphs
If p.Style = "Heading 1" Then
txt = p.Range.Text
MsgBox "Found=" & txt
End If
Next p
End With
End Sub
输出:
你可以修改代码根据您的要求。
you can modify the code as per your requirement.
问候
Deepak
这篇关于检查文档中是否出现特定样式对于单个段落文档是否失败。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!