word macro To insert text at the beginning and at end of paragraph
Hello,
I need to add a sighn like "/>" at the beginning of each paragraph which normally is in style Normal, and after the last character at the end of the paragraph "/>"
I tried this VB, but it cause some problem on the headings , so I need to use different methods and to put the BeforeText and AfterText within the paragraph and not at the headings. Do someone have any suggestion or example?
Dim doc As Document
Dim para As Paragraph
Const BeforeText = "</"
Const AfterText = "/>"
Application.ScreenUpdating = False
Set doc = ActiveDocument
For Each para In doc.Paragraphs
If para.Style = doc.Styles(wdStyleHeading1) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading2) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading3) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading4) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
If para.Style = doc.Styles(wdStyleHeading5) Then
para.Range.InsertBefore (BeforeText)
para.Range.InsertAfter (AfterText)
End If
Next para
End Sub
|