Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2015, 04:20 AM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default Numbered Outline Continuation Headings

I need to develop a macro for adding a continuation heading based on a template using 7 outline levels. The outline numbering is as follows:



Heading 1: 1.0
Heading 2 and Heading 2 TOC: 1.1
Heading 3 and Heading 3 TOC: 1.1.1
Heading 4: A.
Heading 5: 1.
Heading 6: a.
Heading 7: 1)

We require a continuation heading for any page that starts with a Heading 4 or higher. Some examples would be 6.1.2.B. (continued), 7.2.1.A.13. (continued), 5.3.2.B.2.b. (continued), etc.

In a perfect world this would be automatic, but manual would be better than the time consuming method of manually cross-referencing the preceeding parent step and manually typing (continued).

Last edited by Charles Kenyon; 03-11-2015 at 09:31 AM. Reason: Mark as solved
Reply With Quote
  #2  
Old 02-24-2015, 06:08 PM
Guessed's Avatar
Guessed Guessed is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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

Pagination is dynamic - that is, it depends on the page setup, printer chosen and content already in the document before it can be determined. This makes your request difficult to answer simply.

In addition, there would be numerous special cases that would need to be addressed. Eg. What happens when the page starts with a Heading 1, 2 or 3. What happens when a table continues across a pagebreak? If you broke the table to insert this continued paragraph then the table headings won't repeat.

I envision that a macro could be created to roll through the document and create the required cross-reference paragraphs. I would recommend a crossref field since you can add a switch which assembles the full heading number context (ie returns the 6.1.2.B even though the heading itself only says B). The cross ref field requires that you identify the nearest preceding heading and bookmark it.

You would probably need to include the ability to strip out these entries since you would need to rerun the macro every time the document was edited or opened on another machine.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-24-2015, 07:45 PM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default

I know this can be done because I worked with a template once that could do this during the pagination process. I can settle for manual. I need a macro that will look for the Heading style just downstream of the cursor location and then cross-reference the parent Heading style just upstream.
Reply With Quote
  #4  
Old 02-24-2015, 08:08 PM
Guessed's Avatar
Guessed Guessed is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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 can help you with a manual method but I need to understand the following: What does the downstream heading style have to do with it? I thought you only wanted the cross-ref to point back to the preceding heading.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 02-25-2015, 06:56 AM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default

I would think you would have to know what your downstream style is so you would know what parent to look for upstream. Say the first thing on a page is a Note box and the step after the Note (downstream) is B. (Heading 4). I would need to look upstream for the last Heading 3 (say 6.1.4) and make a cross-reference to it. Another example would be where the first step is 3) (Heading 7) and I would need to cross-reference to the preceding Heading 6 so my continuation header would look something like 6.1.4.B.2.a. If you look at the Headings I listed in the question, you notice the is no period at the end of the Heading 3 numbering. When we manually cross-reference we get 6.1.4B.2.a. with no period added between the 4 and B. I can't find a solution for that either.
Reply With Quote
  #6  
Old 02-25-2015, 05:10 PM
Guessed's Avatar
Guessed Guessed is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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
  #7  
Old 02-26-2015, 06:55 PM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default

When I run this code it picks the preceding heading style and not the parent. Example: the step at the top of the page is 4. and the parent step is 6.2.1.A. Your code returns 6.2.1.a.3, not 6.2.1.A. I also appears to be a onetime use due to the bookmark. I may have a large procedure that requires many different continuation headers.
Reply With Quote
  #8  
Old 02-26-2015, 07:19 PM
Guessed's Avatar
Guessed Guessed is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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

Yes, I told you it was a one-time use bookmark and that it needed additional code to work in multiple cases. The purpose of the macro I posted was to show the concept of how you might perform the task.

I assume that when the first paragraph on the page is not a heading then you want the code as provided. If it is a heading then you want to return the level above that. Is that right?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #9  
Old 02-26-2015, 07:30 PM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default

All the steps are Headings. If I have a Heading 5 at the top of the page, I want to return the previous Heading 4.
Reply With Quote
  #10  
Old 03-04-2015, 11:40 PM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default

Problem not solved. Is there anyone out there with a possible solution?
Reply With Quote
  #11  
Old 03-04-2015, 11:51 PM
gmayor's Avatar
gmayor gmayor is offline Numbered Outline Continuation Headings Windows 7 64bit Numbered Outline Continuation Headings Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See if http://www.gmayor.com/catchwords.htm helps.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #12  
Old 03-05-2015, 08:17 PM
Guessed's Avatar
Guessed Guessed is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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

Try the next iteration of the concept. It still has the bookmark uniqueness issue that I spoke about but the rest of it should show you how the code can arrive at the preceding heading's parent.
Code:
Sub ProofOfConcept()
  'macro by Andrew Lockton
  Dim aRng As Range, iLev As Integer
  Set aRng = ActiveDocument.Bookmarks("\page").Range
  aRng.InsertParagraphBefore
  With aRng.Paragraphs(1)
    .Style = "Normal"
    .OutlinePromote
    iLev = .OutlineLevel
    If iLev > 3 Then
      .Style = "Normal"
      aRng.Collapse Direction:=wdCollapseStart
      aRng.Select
      Selection.GoTo What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1
      While Selection.Paragraphs(1).OutlineLevel <> iLev - 1
        Selection.GoTo What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1
      Wend
      
      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
  #13  
Old 03-05-2015, 08:32 PM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default

In reply to gmayor, I don't see how your suggestion could be applied in my situation. I'm not trying to put anything in the header or footer but at the top of the page. I do see some good information about waiting until the document is finished before running the macro but it doesn't really show me how to note the first appearance of a heading on a page (it could come after a table or graphic) and then find it's parent header on the preceding page (could be several pages back).
Reply With Quote
  #14  
Old 03-11-2015, 09:25 AM
rdross51 rdross51 is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Advanced Beginner
Numbered Outline Continuation Headings
 
Join Date: Feb 2015
Location: Abu Dhabi
Posts: 45
rdross51 is on a distinguished road
Default

The last iteration worked! Thanks for the solution.
Reply With Quote
  #15  
Old 03-22-2015, 10:11 PM
Guessed's Avatar
Guessed Guessed is offline Numbered Outline Continuation Headings Windows 7 32bit Numbered Outline Continuation Headings Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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

You should be able to find code online to construct a valid and unique bookmark name. An example of such a macro can be found here http://www.vbaexpress.com/forum/show...-VBA-Bookmarks

Note that Greg's code is not bulletproof but it is a good case study to get you over the next hurdle. Shortcomings of that code, which may or may not matter to you are:
- Doesn't verify whether the bookmark name already exists
- Doesn't truncate string to the maximum length allowed by bookmarks
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Numbered Outline Continuation Headings Capturing numbered headings jbvalen Word VBA 5 05-04-2017 05:03 PM
Word Mixing Numbered Headings with Numbered List Tess0 Word 11 07-15-2014 05:25 AM
Numbered Outline Continuation Headings Headings and Number Outline Problem (MS Office 2008) triodia Word 2 05-07-2012 02:03 AM
Numbered Outline Continuation Headings numbered headings Caroline Word 5 03-14-2011 09:09 AM
XML marking of Auto-numbered Headings crose Word 0 12-17-2009 09:55 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft