2013-10-16 91 views
0

我有一些具有自定義標題樣式的單詞文檔。替換word文檔中的所有標題樣式

我想遍歷文檔中的所有自定義標題,並用標準標題樣式替換自定義樣式。

例如:

Custom Style    Standard Style 
===================   ============== 
Heading 1. Numbered --> Heading 1 
Heading 2. Numbered --> Heading 2 
Heading 3. Numbered --> Heading 3 

,並依此類推,直到第5欄...

我使用MS Word 2007中

問題:我怎麼能做到這一點用VBA ?

回答

0

這爲我工作:https://stackoverflow.com/a/276397/1033422

:改編自

Sub Macro1() 

    Dim DocPara As Paragraph 

    For Each DocPara In Application.ActiveDocument.Paragraphs 
     If DocPara.Range.Style Is Nothing Then 
      ' do nothing 
     Else 
      Dim I As Integer 
      Dim H As String 
      For I = 1 To 5 
       H = "Heading " + CStr(I) + ". Numbered" 
       If Left(DocPara.Range.Style, Len(H)) = H Then 
        DocPara.Range.Style = "Heading " + CStr(I) 
       End If 
      Next I 
     End If 
    Next 

End Sub 

代碼

相關問題