这感觉它应该有一个简单的答案,但我找不到它。作为将数百个单词文档转换为纯HTML的努力的一部分,我使用vba来抓取文档并添加适当的标记。列表段落存在问题,因为在每个列表之前插入标记会将其放入第一行(即,它将项目#1向下颠倒,新项目为“1”)。 insert after方法适用于列表的末尾。 VBA粘贴在下面。有任何想法吗?感谢
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 :(得分:1)
嗯,派对有点晚了,但是试一试:)
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