h2whoa
09-21-2017, 04:58 AM
Hi all,
I genuinely thought this was going to be simple. But it turns out I'm simpler! I have a number of long documents, arranged as so, with Heading 1, 2, 3 and Normal style text:
Heading 1 - A
Heading 2 - 1
Heading 3 - 1
1 Normal text to move
1 Normal text to leave
Heading 2 - 2
Heading 3 - 2
2 Normal text to move
2 Normal text to leave
Heading 1 - B
Heading 2 - 3
Heading 3 - 3
3 Normal text to move
3 Normal text to leave
...
I'm trying to write something that will take the "normal text to move", leaving the "normal text to leave", and append it to the relevant level 2 heading. So it would look like:
Heading 1 - A
Heading 2 - 1 1 Normal text to move
Heading 3 - 1
1 Normal text to leave
Heading 2 - 2 2 Normal text to move
Heading 3 - 2
2 Normal text to leave
Heading 1 - B
Heading 2 - 3 3 Normal text to move
Heading 3 - 3
3 Normal text to leave
...
I've tried so many variations of code, but I don't really seem to be getting anywhere. The latest code I have is below. It does... something, but not what I'm aiming for. Any help gratefully received!
Sub AAMoveParagraphs()
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
If para.sTyle = "Heading 2" Then
Selection.MoveDown Unit:=wdParagraph, Count:=2
Selection.StartOf Unit:=wdParagraph, Extend:=wdMove
Selection.Expand Unit:=wdParagraph
Selection.Range.Copy
Selection.MoveUp Unit:=wdParagraph, Count:=2
Selection.EndOf Unit:=wdParagraph, Extend:=wdMove
Selection.InsertAfter (" ")
Selection.Paste
End If
Next para
End Sub
I genuinely thought this was going to be simple. But it turns out I'm simpler! I have a number of long documents, arranged as so, with Heading 1, 2, 3 and Normal style text:
Heading 1 - A
Heading 2 - 1
Heading 3 - 1
1 Normal text to move
1 Normal text to leave
Heading 2 - 2
Heading 3 - 2
2 Normal text to move
2 Normal text to leave
Heading 1 - B
Heading 2 - 3
Heading 3 - 3
3 Normal text to move
3 Normal text to leave
...
I'm trying to write something that will take the "normal text to move", leaving the "normal text to leave", and append it to the relevant level 2 heading. So it would look like:
Heading 1 - A
Heading 2 - 1 1 Normal text to move
Heading 3 - 1
1 Normal text to leave
Heading 2 - 2 2 Normal text to move
Heading 3 - 2
2 Normal text to leave
Heading 1 - B
Heading 2 - 3 3 Normal text to move
Heading 3 - 3
3 Normal text to leave
...
I've tried so many variations of code, but I don't really seem to be getting anywhere. The latest code I have is below. It does... something, but not what I'm aiming for. Any help gratefully received!
Sub AAMoveParagraphs()
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
If para.sTyle = "Heading 2" Then
Selection.MoveDown Unit:=wdParagraph, Count:=2
Selection.StartOf Unit:=wdParagraph, Extend:=wdMove
Selection.Expand Unit:=wdParagraph
Selection.Range.Copy
Selection.MoveUp Unit:=wdParagraph, Count:=2
Selection.EndOf Unit:=wdParagraph, Extend:=wdMove
Selection.InsertAfter (" ")
Selection.Paste
End If
Next para
End Sub