2012-05-29 5 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을 시도했습니다. 서식을 지정할 때 작동하지 않습니다. 또한 "List Bullet"스타일이있는 행과 찾을 수있는 다른 목록 스타일에 대해서는 find and replace을 시도했습니다. 작동하지 않습니다. (아마도 Mac 용 Word를 사용하기 때문에 버그가있는 것 같습니다.)

EDIT : 글 머리 기호 스타일이있는 문서를 찾는 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

관련 문제