Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting text after certain styles

Status
Not open for further replies.

harky

Technical User
Oct 29, 2001
39
GB
Does anyone know how to search for a particular style and then insert some text on the following line, only when the following style is not one of two particular syles. eg I need to find all instances of a code "n-para" and then insert some text after it, but only when the following para styles are not "n-para" or "PH1".
 
This can get you started

Dim oPara As Paragraph
Dim oNext As Paragraph

For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "Heading 1" Then
Set oNext = oPara.Next
If Not oNext Is Nothing Then
Select Case oNext.Style
Case "Heading 2", "Heading 3"
' do nothing
Case Else
oNext.Range.InsertBefore Text:="inserted text"
End Select
End If
Set oNext = Nothing
End If
Next oPara
Set oPara = Nothing
 
To get you started:

Dim oPara As Paragraph
Dim oNext As Paragraph

For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "Heading 1" Then
Set oNext = oPara.Next
If Not oNext Is Nothing Then
Select Case oNext.Style
Case "Heading 2", "Heading 3"
' do nothing
Case Else
oNext.Range.InsertBefore Text:="inserted text"
End Select
End If
Set oNext = Nothing
End If
Next oPara
Set oPara = Nothing
 
Having problems posting. Please ignore duplicate posts.

Dim oPara As Paragraph
Dim oNext As Paragraph

For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "Heading 1" Then
Set oNext = oPara.Next
If Not oNext Is Nothing Then
Select Case oNext.Style
Case "Heading 2", "Heading 3"
' do nothing
Case Else
oNext.Range.InsertBefore Text:="inserted text"
End Select
End If
Set oNext = Nothing
End If
Next oPara
Set oPara = Nothing
 
Having problems posting. Please ignore duplicate posts.

This will get you started:

Dim oPara As Paragraph
Dim oNext As Paragraph

For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "Heading 1" Then
Set oNext = oPara.Next
If Not oNext Is Nothing Then
Select Case oNext.Style
Case "Heading 2", "Heading 3"
' do nothing
Case Else
oNext.Range.InsertBefore Text:="inserted text"
End Select
End If
Set oNext = Nothing
End If
Next oPara
Set oPara = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top