P
pachmarhi
I want to convert word documents to HTML and need to insert appropriate
paragraph styles throughout. I found a macro to help me to add text to the
beginning of the paragraph, but having difficulty getting it to do the same
for the end. What can I add so that at the end of each paragraph formatted
with Heading 2, it will insert </h1> before the paragraph mark?
'This example inserts "<h1>" at the beginning of
' every paragraph formatted with the Heading 2 style.
With ActiveDocument.Content.Find
..ClearFormatting
..Style = wdStyleHeading2
'The Do...Loop statement repeats a series of
' actions each time this style is found.
Do While .Execute(Forward:=True, Format:=True) = True
With .Parent
'If the found text is the last
' paragraph in the document...
If .End = ActiveDocument.Content.End Then
..StartOf Unit:=wdParagraph, Extend:=wdMove
..InsertAfter "<h1>"
Exit Do
'If the found text is *not* the last
' paragraph in the document...
Else
..StartOf Unit:=wdParagraph, Extend:=wdMove
..InsertAfter "<h1>"
..Move Unit:=wdParagraph, Count:=1
End If
End With
'Goes back to the beginning of the Do...Loop statement.
Loop
End With
paragraph styles throughout. I found a macro to help me to add text to the
beginning of the paragraph, but having difficulty getting it to do the same
for the end. What can I add so that at the end of each paragraph formatted
with Heading 2, it will insert </h1> before the paragraph mark?
'This example inserts "<h1>" at the beginning of
' every paragraph formatted with the Heading 2 style.
With ActiveDocument.Content.Find
..ClearFormatting
..Style = wdStyleHeading2
'The Do...Loop statement repeats a series of
' actions each time this style is found.
Do While .Execute(Forward:=True, Format:=True) = True
With .Parent
'If the found text is the last
' paragraph in the document...
If .End = ActiveDocument.Content.End Then
..StartOf Unit:=wdParagraph, Extend:=wdMove
..InsertAfter "<h1>"
Exit Do
'If the found text is *not* the last
' paragraph in the document...
Else
..StartOf Unit:=wdParagraph, Extend:=wdMove
..InsertAfter "<h1>"
..Move Unit:=wdParagraph, Count:=1
End If
End With
'Goes back to the beginning of the Do...Loop statement.
Loop
End With