2011-02-11 59 views

回答

1

如何:

Dim s As Range 
For Each s In ActiveDocument.Sentences 
    If s.Characters(1).Bold = True Then 
     Debug.Print s 
    End If 
Next 

我不太看你的「選擇」的意思,你可以使用s.Select,但它只會爲一句話工作。

編輯再評論

大致來說:

Dim s As Range 
Dim doc1 As Document 
Dim doc2 As Document 

Set doc1 = Word.Documents("Doc1.doc") 
Set doc2 = Word.Documents("Doc2.doc") 

For Each s In doc1.Sentences 
    If s.Characters(1).Bold = True Then 
     Debug.Print s 
     doc2.Select 
      Selection.Find.ClearFormatting 
      With Selection.Find 
       ''.Text cannot be set to more than 256 characters 
       .Text = s 
       .Replacement.Text = "" 
       .Forward = True 
       .Wrap = wdFindContinue 
       .Format = False 
       .MatchCase = False 
       .MatchWholeWord = False 
       .MatchWildcards = False 
       .MatchSoundsLike = False 
       .MatchAllWordForms = False 
      End With 
      a = Selection.Find.Execute 
      If a = True Then 
       Selection.Characters(1).Font.Bold = True 
       ''Or for the whole sentence 
       Selection.Font.Bold = True 
      End If 
     doc1.Select 
    End If 
Next 

編輯再評論#2

兩個文件進行比較是相同的,所以也許:

Dim doc1 As Document 
Dim doc2 As Document 
Dim i As Integer 

Set doc1 = Word.Documents("Doc1.doc") 
Set doc2 = Word.Documents("Doc2.doc") 

If doc1.Sentences.Count <> doc2.Sentences.Count Then 
    MsgBox "These two documents do not match." 
    Exit Sub 
End If 

For i = 1 To doc1.Sentences.Count 
    If doc1.Sentences(i).Characters(1).Bold = True Then 
     ''Debug.Print doc1.Sentences(i) 
     If doc1.Sentences(i).Text = doc2.Sentences(i).Text Then 
      doc2.Sentences(i).Bold = True 
     Else 
      MsgBox "Sentences do not match." 
     End If 
    End If 
Next 
+0

是我意味着選擇。實際上有兩個包含相同上下文的單詞文檔。其中一個包括一些大膽的斜體標題等。我想在第一個文檔中找到它們,並在第二個文檔中進行粗體處理。 – tebdilikiyafet 2011-02-11 23:07:14