2017-09-26 91 views
0

這感覺就像應該有一個簡單的答案,但我找不到它。作爲將數百個Word文檔轉換爲純HTML的努力的一部分,我使用vba來抓取文檔並添加適當的標籤。列表段落呈現出一個問題,因爲在每個列表之前在第一行中插入標籤(即它將項目#1向下顛簸,並且新項目爲「1」)。 insert after方法在列表的末尾工作得很好。 VBA粘貼在下面。有任何想法嗎?由於Word VBA:Insertbefore編號列表段落和項目1之前

Sub listparagraphtagging() 
    Dim aList As list 
    Dim rng As Range 

    For Each aList In ActiveDocument.Lists 
     aList.Range.InsertParagraphBefore 
     aList.Range.InsertBefore "<ul>" 
     aList.Range.InsertAfter "</ul>" 
    Next 
End Sub 

回答

0

嗯,有點遲到了,但給這一個去:)

Sub listparagraphtagging() 
    Dim aList As List 
    Dim rng As Range 
    Dim para As Paragraph 

    For Each aList In ActiveDocument.Lists 
     For Each para In aList.Range.Paragraphs 
      Set rng = para.Range 
      rng.InsertBefore "<ul>" 
      rng.End = rng.End - 1 
      rng.Collapse wdCollapseEnd 
      rng.Text = "</ul>" 
     Next 
    Next 
End Sub 
相關問題