2012-05-29 69 views
4

我想查找項目符號列表的實例,以用html標記的列表替換。請參閱下面的例子:查找並替換爲html樣式的項目符號列表

my_doc.docx ...

text,text,text 
My bullet list: 
    • List point one 
    • List point two 
Some more text here. 

...

查找和替換導致

...

text,text,text 
My bullet list: 
<ul> 
<li>List point one</li> 
<li>List point two</li> 
</ul> 
Some more text here. 

...

我試過find and replace爲子彈字符;因爲格式化不起作用。也嘗試find and replace的樣式「列表項目符號」和任何其他列表樣式,我可以找到; (可能是因爲我使用Word的Mac似乎越野車)

編輯: 我有以下VBScript,找到我的文檔中有子彈樣式的行。我現在需要使用這個腳本來重寫它在末尾找到的與< li>標籤所在的行。

Sub FindBullet() 
Dim oPara As Word.Paragraph 
Dim count As Integer 

count = 0 
Selection.WholeStory 
With Selection 
    For Each oPara In .Paragraphs 
    If oPara.Range.ListFormat.ListType = _ 
    WdListType.wdListBullet Then 

      count = count + 1 

      # from here down it gets shaky!!! 

      With ActiveDocument.Range.Find 
       .Text = #How do i convert the oPara to a string here?!? 
       .Forward = True 
       .Wrap = wdFindContinue 
       .Format = False 
       .MatchCase = True 
       .MatchWholeWord = False 
       .MatchWildcards = False 
       .MatchSoundsLike = False 
       .MatchAllWordForms = False 

       .ClearFormatting 
       With .replacement 
       .ClearFormatting 
       .Text = # how do i specify this is where i want the "<li>" & oPara & "</li>" 
       End With 
       .Execute Replace:=wdReplaceAll 

     End If 
    Next 
End With 
'Gives you the count of bullets in a document 
MsgBox count & " replacements" 
End Sub 

回答

3

可以使用(的insertBeforeInsertAfter)插入的段落文本。 這適用於Word Mac。

Sub FindBullet() 
Dim count As Integer 
count = 0 
Set myStyle = ActiveDocument.Styles("Body text") ' replacement style 
bulletList = WdListType.wdListBullet 

' each list instead of each paragraph of the document 
For Each thisList In ActiveDocument.Lists 
     For Each p In thisList.ListParagraphs 
      If p.Range.ListFormat.ListType = bulletList Then 
       p.Style = myStyle ' change the style to "Body text" 
       p.Range.InsertBefore ("<li>") 
       Set aRange = p.Range 
       aRange.End = aRange.End - 1 
       aRange.InsertAfter ("</li>") 
       count = count + 1 
      End If 
     Next 
Next 
MsgBox count & " replacements" 
End Sub 
+0

是的,這工作得很好。謝謝! – Norto23

相關問題