2008-10-23 279 views
3

我在Word 2007中創建了一些簡單的.doc文件,其中我更改了文本顏色並使用高亮來比較一些相似的文本。我想要做的是將每個綠色文本或灰色突出顯示的實例更改爲不同的顏色。如何在MS Word中將突出顯示的文本更改爲不同的顏色?

我確定有一種簡單的方法可以用VBA做到這一點,但也歡迎任何其他類型的答案。

編輯:雖然我確實很感謝答案,但我更喜歡將.doc文件保存爲.docs。

回答

1

您始終可以將文件另存爲HTML,並將顏色替換爲其中的顏色。顏色是與

<span style='color:red'>... 

和亮點是

<span style='background:yellow;mso-highlight:yellow'>... 

應該很容易操作,如果你的文檔是很簡單的。

編輯回答問題中的編輯:完成後,重新打開文件並將文件保存爲.doc。

+0

實際上它有點複雜,因爲mso-highlight:某些鍵值對可以隱藏在其他這樣的對(關於編碼,語言,字體選擇等)中。我的建議是尋找mso-highlight:在span元素的style屬性內的某處。 – yannis 2015-11-22 13:49:02

2

這不是2007年,但這個想法應該適合。此示例將任何當前突出顯示更改爲新的默認突出顯示(wdBrightGreen),並將任何綠色文本更改爲紅色。

Sub ChangeColor 
Options.DefaultHighlightColorIndex = wdBrightGreen 

    Selection.Find.ClearFormatting 
    Selection.Find.Highlight = True 
    Selection.Find.Replacement.ClearFormatting 
    Selection.Find.Replacement.Highlight = True 
    Selection.Find.Execute Replace:=wdReplaceAll 

    Selection.Find.ClearFormatting 
    Selection.Find.Font.Color = wdColorBrightGreen 
    Selection.Find.Replacement.ClearFormatting 
    Selection.Find.Replacement.Font.Color = wdColorRed 
    With Selection.Find 
     .Text = "" 
     .Replacement.Text = "" 
     .Forward = True 
     .Wrap = wdFindContinue 
    End With 
    Selection.Find.Execute Replace:=wdReplaceAll 
End Sub 
0

這應該爲你的目的的工作:

Sub RehiliteAll() 

    Const YOUR_REQUIRED_COLOR_IDX As Integer = 6 'RED' 
    Dim doc As Range 
    Set doc = ActiveDocument.Range 

    With doc.Find 
     .ClearFormatting 'resets default search options' 
     .Highlight = True 
     .Wrap = wdFindStop 

     While .Execute 

      If doc.HighlightColorIndex = YOUR_REQUIRED_COLOR_IDX Then 
       doc.Select 
       MsgBox doc.HighlightColorIndex 
       'Do stuff here' 
      End If 

      'doc has been reassigned to the matching' 
      'range; we do this so word keeps searching' 
      'forward' 
      doc.Collapse wdCollapseEnd 
     Wend 
    End With 

    Set doc = Nothing 
End Sub 

'I am closing comment quotes so that SO formatting' 
'does not get messed up too much.' 
1

我想一個能彰顯彩色文本的部分,然後選擇「選擇具有相似的格式文本」從選擇文本菜單選項選項「主頁」選項卡。然後只需選擇所需的文字顏色。 希望這個作品。

相關問題