View Single Post
 
Old 02-25-2015, 05:10 PM
Guessed's Avatar
Guessed Guessed is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I still don't see how the following heading is relevant. If I see a Heading 4 on this page then it might still be preceded by any heading level (although a Heading 1 or 2 would indicate poor document structure).

Have a look at the following attempt at understanding your requirement. This would need to be modified further to name the bookmark created uniquely but I believe it contains all the elements to get you going. You are not going to get a solution with the missing period if you retain the cross-ref but you could choose to unlink it and then add the period into the right position. I would also recommend you create a specific style for this continuation paragraph which includes a 'page break before' setting otherwise it will often end up on the preceding page.
Code:
Sub ProofOfConcept()
  'macro by Andrew Lockton
  Dim aRng As Range
  Set aRng = ActiveDocument.Bookmarks("\page").Range
  aRng.InsertParagraphBefore
  With aRng.Paragraphs(1)
    .Style = "Normal"
    .OutlinePromote
    Debug.Print .OutlineLevel
    If .OutlineLevel > 3 Then
      .Style = "Normal"
      aRng.Collapse Direction:=wdCollapseStart
      aRng.Select
      Selection.GoTo What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1
      ActiveDocument.Bookmarks.Add Name:="ABC", Range:=Selection.Range
      aRng.InsertAfter " continued"
      aRng.Collapse Direction:=wdCollapseStart
      ActiveDocument.Fields.Add Range:=aRng, Text:="Ref ABC \w \h"
      aRng.Select
    Else
      aRng.Paragraphs(1).Range.Delete
    End If
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote