Managing Outline Numbering in my workplace

G

Greig Mackenzie

Hi,



I have read so many posts and threads now that I really don't know which way
to turn.



I used to run a macro that would find and then reapply a numbered style and
then (as applicable) restart the number by specifying the correct ListTemp
and ListLvl and ContinuePreviousList:=False. For obvious reasons this only
really worked for me--many people's ListTemp 4 had changed. I could get
documents, fix them and then give them back and they usually stayed fine, at
least for a while.



So many documents in this company are re-used, bits copied and pasted, etc.
Corruption issues abounded. I have stemmed most of these but not all--too
many ListTemplates seems tp be the issue now (i.e., >1700).



Hence, I now have several different numbering schemes that have been created
and attached to paragraph styles using the certified VB code method in these
posts (happened to be Dave Rado's version in this case I believe). Works
beautifully to standardise formatting for my 7 different ListTemplates (all
Outline) for both Templates and any document that goes awry. BTW Thank You
everyone.



I have a macro that will find the most typical circumstances in which List
Numbers should start from 1, i.e., after certain headings, after my ListPre
style, etc. The problem is that, instead of specifying the ListTemp and
ListLvl, I want to specify 'ListNumberTemplate' and the ListLvl. But I can't
work out how to substitute, 'ListNumberTemplate' for ListTemp=X.



Eg.

Sub ResetListNumber4()



' List Number 4

Selection.Style = ActiveDocument.Styles( _
"List Number 4,LN4")

LISTTEMP = 3 'List Gallery Template 0-7
LISTLVL = 4 'List Level 1-9

' With
ListGalleries(wdOutlineNumberGallery).ListTemplates(LISTTEMP).ListLevels(LIS
TLVL)
' .StartAt = 1
' .LinkedStyle = "List Number 4,LN4"
' End With




ListGalleries(wdOutlineNumberGallery).ListTemplates(LISTTEMP).Name = ""
Selection.Range.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries( _
wdOutlineNumberGallery).ListTemplates(LISTTEMP),
ContinuePreviousList:=False, _
ApplyTo:=wdListApplyToWholeList,
DefaultListBehavior:=wdWord9ListBehavior



End Sub

I tried a change as follows, (showing my ignorance):

ListGalleries(wdOutlineNumberGallery).ListTemplates().Name =
"ListNumberTemplate"



It didn't like it. Or it didn't do anything.



Since I can determine the restart point of 80% of our lists, I want to just
run a macro that will restart the selected paragraph using either the
existing or a specified named ListTemplate.



Also, (and this may be incorporated into an existing 'seek and restart'
macro) I would like to be able to just restart the selected paragraph,
referencing the attached ListTemplate while KEEPING the attached
ListTemplate.



The following only worked for me for level 1. I need to be able to
discriminate between levels and reset only that level for the current
paragraph:

Dim myLT As ListTemplate
Set myLT = ActiveDocument.ListTemplates("ListNumberTemplate")
Selection.Range.ListFormat.ApplyListTemplate _
ListTemplate:=myLT, _
ContinuePreviousList:=False, _
ApplyTo:=wdListApplyToWholeList, _
DefaultListBehavior:=wdWord9ListBehavior

Can anybody understand what I am trying to do?



For commonly posted reasons, I want to avoid LISTNUM and Dummy Styles. My
best bet for this place is to provide a couple of buttons (macros) that will
Restart (selected) or Continue (selected), using whatever ListTemplate and
ListLvl is attached (these can be predefined/fixed by other methods)



I hope I have explained myself adequately.



Thanks in advance for any help

Greig Mackenzie
 
K

Klaus Linke

Hi Greig,

If you are in some paragraph that's numbered, you can get the list template
that is "responsible" for that paragraph directly and don't need the list
template's name.

http://www.syntagma.demon.co.uk/FAQs/ListRestartFromVBA.htm by Margaret
Aldis has some nice code from Steve Hudson that doesn't error out if you use
it on a non-numbered paragraph.

With a small addition, you could use the same macro to add and remove
restarts:

Sub ToggleRestarts()
' original Macro created by Steve Hudson
Dim TheRange As Range
Set TheRange = Selection.Range
TheRange.Collapse
On Error Resume Next
If TheRange.Paragraphs(1).Range.start = _
TheRange.ListFormat.List.Range.start Then
With TheRange.ListFormat
.ApplyListTemplate .ListTemplate, True
End With
Else
With TheRange.ListFormat
.ApplyListTemplate .ListTemplate, False
End With
End If
End Sub

Haven't used this myself, but hope it works.

Greetings,
Klaus
 
K

Klaus Linke

BTW, since problems with stray list templates and restarts that don't work
after you copy/paste from another document are bound to crop up, I'd try to
write a macro that reapplies the list styles to all list paragraphs, and
then re-applies the restarts according to your rules.

The code further down in Margaret Aldis' article should give you a good
starting point for this.

Klaus
 
G

Greig Mackenzie

Hi Klaus, I feel like I know you from reading so much of your posts. ;-}
Thanks for you replies. I have performed some experiments and it seems to be
quite workable.
I only have issues with 1st level numbers, thereafter they seem to be
handled quite well by 'ResetOnHigher'. So my existing macro only finds, for
instance, H1, checks the next paragraph for LN, if yes, RESTART. Find next
H1, etc. Once it has completed a lap it then looks for H2, etc. It will
repeat this for approx. 20 different styles which captures all typical
starting list number scenarios.
I will substitute what I previously had to perform RESTART with the code you
supplied and do some further trials. When I did brief tests I noticed some
irregularities with the 'Auto. update doc. styles' checked and a test doc I
use that contains several pages of list numbering variations. I know all the
information out there says 'don't do this' but I don't see why this should
be. No doubt you could answer this but you shouldn't need to.
When I run your supplied code, the 'ListTemplateName' remains. Save, close
and then re-open with 'Auto. update' on, sometimes the 'ListTemplateName'
would be blank. I like this on because it typically fixes imported styles
from external sources as well errors from other staff.
I will adapt my existing code to incorporate your supplied code and perform
these tests.

BTW, can you give me any hints to identify the first occurrence of a
particular ListTemplate or Style in a Table Cell? (List numbering used for
psuedo-code in cells to describe plug-ins etc)

Thanks again, big help.
Greig.
 
K

Klaus Linke

Hi again,

Some remarks in arbitrary order:
I only have issues with 1st level numbers, thereafter they seem to be
handled quite well by 'ResetOnHigher'. So my existing macro only finds,
for instance, H1, checks the next paragraph for LN, if yes, RESTART.
Find next H1, etc. Once it has completed a lap it then looks for H2,
etc. It will repeat this for approx. 20 different styles which captures
all typical starting list number scenarios.

This does sound like a case where you could use H1 and H2 as (non-numbered)
dummy restart styles at the head of the used list template.
But with 20 possible restart styles, that's out of the question ;-) ... And
you'd still run into problems if you paste from arbitrary documents, so you
would need to have a macro to fix broken numbering.

Only one additional suggestion: You might re-write your macro to do a single
pass through all paragraphs (For Each myPara in ActiveDocument.Paragraphs).
If you hit a H1 or H2 paragraph, you'd set a toggle Boolean variable to
remind you to apply a restart on the next numbered paragraph.
If you then do hit a numbered paragraph, you'd apply the restart, and reset
the toggle to "False".
It should be easy to extend that to other starting rules, and you'd only
need one pass instead of 20.

When I did brief tests I noticed some irregularities with the
'Auto. update doc. styles' checked and a test doc [...]

I don't really have much of a clue about the possible problems of
AutoUpdating numbered document styles.
Perhaps http://www.mvps.org/word/FAQs/MacrosVBA/UpdateStyles.htm can help
you with that.

BTW, can you give me any hints to identify the first occurrence of a
particular ListTemplate or Style in a Table Cell? (List numbering used
for psuedo-code in cells to describe plug-ins etc)

Not sure if I understand the question correctly...
You should be able to cycle through the paragraphs and check their style, or
the ListTemplate.
I can't think of anything that's special about table cells.
Except that it may add some complexity to your macro if you have to check if
the current paragraph is in a table using .Information(wdWithInTable), and
possibly wether the paragraph is the first one in a cell... if your rules
for restarts depend on it.

If I understood correctly what you're trying to set up, the numbering should
be determined wholly by the (list) styles used, and your rules for restarts.
I'd probably not worry about an option to apply or remove restarts from
individual paragraphs at all, then.
Instead, you'd run your macro to fix the numbering once in a while (re-apply
the list styles, and then apply the restarts according to your rules).

Regards,
Klaus
 
G

Greig Mackenzie

You're spot on. Sorry, I won't ask anymore of your time.
My comments below.

Klaus Linke said:
Hi again,

Some remarks in arbitrary order:


This does sound like a case where you could use H1 and H2 as (non-numbered)
dummy restart styles at the head of the used list template.
But with 20 possible restart styles, that's out of the question ;-) ... And
you'd still run into problems if you paste from arbitrary documents, so you
would need to have a macro to fix broken numbering.
Yep.
Only one additional suggestion: You might re-write your macro to do a single
pass through all paragraphs (For Each myPara in ActiveDocument.Paragraphs).
If you hit a H1 or H2 paragraph, you'd set a toggle Boolean variable to
remind you to apply a restart on the next numbered paragraph.
If you then do hit a numbered paragraph, you'd apply the restart, and reset
the toggle to "False".
It should be easy to extend that to other starting rules, and you'd only
need one pass instead of 20.
Yep. Perfect. This is exactly what I would like to do, but my VB knowledge
does not yet permit me. I think you have given me enough to go on
researching on my own.
When I did brief tests I noticed some irregularities with the
'Auto. update doc. styles' checked and a test doc [...]

I don't really have much of a clue about the possible problems of
AutoUpdating numbered document styles.
Perhaps http://www.mvps.org/word/FAQs/MacrosVBA/UpdateStyles.htm can help
you with that.
Ok, understood.
BTW, can you give me any hints to identify the first occurrence of a
particular ListTemplate or Style in a Table Cell? (List numbering used
for psuedo-code in cells to describe plug-ins etc)

Not sure if I understand the question correctly...
You should be able to cycle through the paragraphs and check their style, or
the ListTemplate.
I can't think of anything that's special about table cells.
Except that it may add some complexity to your macro if you have to check if
the current paragraph is in a table using .Information(wdWithInTable), and
possibly wether the paragraph is the first one in a cell... if your rules
for restarts depend on it.
Mmm. Ok. I use .Inforformation(wdWithinTable) already to skip these. More
investigation on my part required, naturally.
If I understood correctly what you're trying to set up, the numbering should
be determined wholly by the (list) styles used, and your rules for restarts.
I'd probably not worry about an option to apply or remove restarts from
individual paragraphs at all, then.
Instead, you'd run your macro to fix the numbering once in a while (re-apply
the list styles, and then apply the restarts according to your rules).

Yep again, precisely.

I may have mentioned the wrong thing earlier. I want to offer the user a
Restart or Continue option for them to use during edits or authoring. The
rest if for to fix old documents or peoples mistakes.
Regards,
Klaus


Thanks for all your time. I really appreciate it.

Cheers
Greig.
 
K

Klaus Linke

Yep. Perfect. This is exactly what I would like to do, but my
VB knowledge does not yet permit me. I think you have given
me enough to go on researching on my own.

The whole project will probably become too large to discuss in a newsgroup
thread.
But if you can whittle it down to a couple of small questions, I'm sure
you'll get help with ironing out any bugs or optimizing the code.

Anyway, it's an interesting approach :)
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top