HELP - paragragh numbering goobered up

R

Roscoe

I am tired of constantly having to tweak my paragragh numbering
because of Word bugs, but this most recent one is killing me. Note I
don't use VBA to set my numbering schemes, but at this point it sure
sounds attractive to learn how. (most of my VBA skills are from
recording macros, examining, and cleaning them up to my purpose).

I built a document that seems to work OK numbering wise, and all of
the styles are uniquely named so as to not be duplicated within
another document in which it has to be inserted (merged?).

My document has two sections. The first section is numbered
differently than the second section (Section one has paragraghs L-1,
L-2, etc, and the second is M-1, M-2, etc..., both with sunsequent sub
paragraghs). It is to be merged into a document where the builder
used the normal style primarily, each para manually formatted, with
manual numbering. (They used some header stlyes, but only for the
formatting, not the numbering). As you can probably tell, their Word
skills are rudimentary...not unusual in governement offices.

When I merge in my document, the first section works OK (L-1 etc), but
the second drops all of the numbering, but appears to leaves the
styles otherwise OK. When I try to reapply the numbering to the
second section, some of the stlyes change and messes averything up. I
can fix it with time and patience, but the person who will be doing
the actual merging doesn't have the skill (ps. I told them NOT to
merge as it willl be distributed in printed form anyway, but they
insist as it is "policy"). Not to mention that this is a document
that will be edited frequently and then reinserted each time (truly a
pain because the first insertion also insert the styles which stay and
overide any changes I may make in my document...arrrggghhh)

I am lost at this point. Minor edits are becoming way too much work.
I am beginning to think that the best way would be to build a VBA
routine that resets the numbering gallery and rebuilds it with the two
schemes I use, but my VBA skills are very rusty and I quite frankly
don't have the time to relearn them from scratch. If someone has a
routine built that I can edit with the parameters (number, indents,
etc...) I would be ETERNALLY GRATEFUL.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Roscoe > écrivait :
In this message, < Roscoe > wrote:

|| I am tired of constantly having to tweak my paragragh numbering
|| because of Word bugs, but this most recent one is killing me. Note I
|| don't use VBA to set my numbering schemes, but at this point it sure
|| sounds attractive to learn how. (most of my VBA skills are from
|| recording macros, examining, and cleaning them up to my purpose).
||
|| I built a document that seems to work OK numbering wise, and all of
|| the styles are uniquely named so as to not be duplicated within
|| another document in which it has to be inserted (merged?).
||
|| My document has two sections. The first section is numbered
|| differently than the second section (Section one has paragraghs L-1,
|| L-2, etc, and the second is M-1, M-2, etc..., both with sunsequent sub
|| paragraghs). It is to be merged into a document where the builder
|| used the normal style primarily, each para manually formatted, with
|| manual numbering. (They used some header stlyes, but only for the
|| formatting, not the numbering). As you can probably tell, their Word
|| skills are rudimentary...not unusual in governement offices.
||
|| When I merge in my document, the first section works OK (L-1 etc), but
|| the second drops all of the numbering, but appears to leaves the
|| styles otherwise OK. When I try to reapply the numbering to the
|| second section, some of the stlyes change and messes averything up. I
|| can fix it with time and patience, but the person who will be doing
|| the actual merging doesn't have the skill (ps. I told them NOT to
|| merge as it willl be distributed in printed form anyway, but they
|| insist as it is "policy"). Not to mention that this is a document
|| that will be edited frequently and then reinserted each time (truly a
|| pain because the first insertion also insert the styles which stay and
|| overide any changes I may make in my document...arrrggghhh)
||
|| I am lost at this point. Minor edits are becoming way too much work.
|| I am beginning to think that the best way would be to build a VBA
|| routine that resets the numbering gallery and rebuilds it with the two
|| schemes I use, but my VBA skills are very rusty and I quite frankly
|| don't have the time to relearn them from scratch. If someone has a
|| routine built that I can edit with the parameters (number, indents,
|| etc...) I would be ETERNALLY GRATEFUL.

Here is a macro I have used. You will have to adjust it to your
requirements. Here is the background for this macro:

I needed templates that would generates documents that would end up being
pasted together in one long document to produce training manuals. There were
dozens of authors and 6 different templates.

I needed only one level of numbering, but I did not want the numbering to
get messed up after the pasting; especially the list numbering starting
points. If an author set the numbering to start at one, it had to stay at
one after the pasting.

Since all styles would have the same names, I had to find a way to enforce
this.

I used the Hidden level technique.

This macro builds a base style on which all other styles are based (to avoid
being based on Normal, but the base itself is based on Normal). Then it
builds the hidden level (Numbered Style Level 0) and the first level
(Numbered Style). Finally, it build a list template and associate the level
0 to the first level and the Numbered Style to level 1. Notice that all
indentation and tabs for positioning the numbers in the numbered styles is
dealt with in the list template definitions, not in the style definition.

To start numbering in the document, apply level 0 then hit Enter to get
Level 1. Whenever a list has to restart at one, just precede the first
numbered paragraph by a level 0 paragraph.

This macro was designed to run in a template, so it deletes all instances of
the styles having the same name. If you run it in a document, it will remove
all formatting form pre-existing paragraphs that were formatted with these
styles. If you want to run it in a document that already uses these styles,
you will have to comment out these lines:

'_______________________________________
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = StyleNameBase Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'_______________________________________

and

'_______________________________________
ActiveDocument.Styles.Add Name:=StyleNameBase, _
Type:=wdStyleTypeParagraph
'_______________________________________

(Three times, Base, Level 0 and Numbered styles)

Also, if you do not want the Level 0 thingy, remove all the code that deals
with its creation and assign Numbered Style as the first level in the List
template section of the macro.

Finally, if you need many levels of numbering,
Add a constant at the top to name the style,
e.g. Const StyleName As String = "Numbered Style Level 1"
Take the Numbered Style block and paste it,
Change the style definition and constant name,
Add a level in the List template block by copying and pasting one of the
level (and just adjust the pasted text).


'_______________________________________
Sub CreateStyle()

Dim oLstTemplate As ListTemplate, TemplateFound As Boolean
Dim oStyle As Style, StyleFound As Boolean

Const StyleNameBase As String = "Numbered Style Base"
Const Style0Name As String = "Numbered Style Level 0"
Const StyleName As String = "Numbered Style"
Const ListTemplateName As String = "MyListTemplate"

'------------------------------------------------------------
'------------------------------------------------------------
'BASE STYLE
'-------------------------------------------------
'Delete style if it already exists
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = StyleNameBase Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'------------------------------------------------

'Then create the base style
ActiveDocument.Styles.Add Name:=StyleNameBase, _
Type:=wdStyleTypeParagraph
Set oStyle = ActiveDocument.Styles(StyleNameBase)
'-------------------------------------------------
'and adjust it to taste
With oStyle
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
With .ParagraphFormat
.SpaceAfter = 6
End With
End With
'------------------------------------------------------------
'------------------------------------------------------------


'------------------------------------------------------------
'------------------------------------------------------------
'NUMBERED STYLE
'-------------------------------------------------
'Delete style if it already exists
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = StyleName Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'-------------------------------------------------

'Then create the numbered style
ActiveDocument.Styles.Add Name:=StyleName, _
Type:=wdStyleTypeParagraph
Set oStyle = ActiveDocument.Styles(StyleName)
'-------------------------------------------------
'and adjust it to taste
With oStyle
.AutomaticallyUpdate = False
.BaseStyle = StyleNameBase
With .ParagraphFormat
.SpaceAfter = 3
.SpaceBefore = 3
End With
End With
'------------------------------------------------------------
'------------------------------------------------------------


'------------------------------------------------------------
'------------------------------------------------------------
'LEVEL 0 STYLE
'-------------------------------------------------
'Delete style if it already exists
StyleFound = False
For Each oStyle In ActiveDocument.Styles
If ActiveDocument.Styles(oStyle) = Style0Name Then
StyleFound = True
oStyle.Delete
Exit For
End If
Next oStyle
'-------------------------------------------------

'Then create the level 0 style
ActiveDocument.Styles.Add Name:=Style0Name, _
Type:=wdStyleTypeParagraph
Set oStyle = ActiveDocument.Styles(Style0Name)
'-------------------------------------------------
'and adjust it to taste
With oStyle
.AutomaticallyUpdate = False
.BaseStyle = "Normal"
.NextParagraphStyle = StyleName
With .ParagraphFormat
.SpaceAfter = 0
.SpaceBefore = 0
.KeepWithNext = True
.LineSpacingRule = wdLineSpaceSingle
End With
.Font.Size = 1
.Font.Color = wdColorWhite
End With
'------------------------------------------------------------
'------------------------------------------------------------


'------------------------------------------------------------
'------------------------------------------------------------
'LIST TEMPLATE
'-------------------------------------------------
'Find or create the list template
For Each oLstTemplate In ActiveDocument.ListTemplates
If oLstTemplate.Name = ListTemplateName Then
TemplateFound = True
Exit For
End If
Next oLstTemplate
'-------------------------------------------------
If TemplateFound Then
Set oLstTemplate = ActiveDocument _
.ListTemplates(ListTemplateName)
Else
Set oLstTemplate = ActiveDocument _
.ListTemplates.Add(OutlineNumbered:=True)
oLstTemplate.Name = ListTemplateName
End If
'-------------------------------------------------
'and adjust the list template
With oLstTemplate.ListLevels(1)
.NumberFormat = ""
.TrailingCharacter = wdTrailingNone
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.33)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = Style0Name
End With
'-------------------------------------------------
With oLstTemplate.ListLevels(2)
.NumberFormat = "%2."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = InchesToPoints(0)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.16)
.TabPosition = wdUndefined
.ResetOnHigher = True
.StartAt = 1
.LinkedStyle = StyleName
End With
'------------------------------------------------------------
'------------------------------------------------------------

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Margaret Aldis

Hi Roscoe

Taking a sideways leap - if the target document uses manual numbering
anyway, would this be an occasion to convert the numbering to text in a copy
of your document before insertion?

The VBA instruction to do this on the whole document is:

ActiveDocument.ConvertNumbersToText

VBA Help on the method will tell you more.

If that won't wash because you need to keep your live numbering in the
target (and not just in your editable copy) then one thing you could try is
resetting your numbered paragraphs to style after the paste - losing
numbering when pasting seems to be the latest incarnation of Word
misapplying direct number formatting (as Christopher Robin said - 'now how
to amuse them today?'). If your document is styled cleanly, you could just
select that portion of the merged document and do Ctrl-Q. Or you could use
something like:

For Each apara In ActiveDocument.Paragraphs
stylename = apara.Style
If stylename Like "myheading*" Then ' or whatever test you need to find
your numbered paras
apara.Style = stylename ' reapply the style
End If
Next apara
 
A

Air Force Jayhawk

Hi Roscoe

Taking a sideways leap - if the target document uses manual numbering
anyway, would this be an occasion to convert the numbering to text in a copy
of your document before insertion?

The VBA instruction to do this on the whole document is:

ActiveDocument.ConvertNumbersToText

VBA Help on the method will tell you more.

If that won't wash because you need to keep your live numbering in the
target (and not just in your editable copy) then one thing you could try is
resetting your numbered paragraphs to style after the paste - losing
numbering when pasting seems to be the latest incarnation of Word
misapplying direct number formatting (as Christopher Robin said - 'now how
to amuse them today?'). If your document is styled cleanly, you could just
select that portion of the merged document and do Ctrl-Q. Or you could use
something like:

For Each apara In ActiveDocument.Paragraphs
stylename = apara.Style
If stylename Like "myheading*" Then ' or whatever test you need to find
your numbered paras
apara.Style = stylename ' reapply the style
End If
Next apara

Wow, if I had known this trick (the first, one-liner), I could have
fininshed in minutes and gone home eraly today!

Can't wait to try it out tomorrow. Is the numbers->text pretty
transparent i.e. in a printout you won't be able to tell?

Roscoe
 
S

Shauna Kelly

Is the numbers->text pretty
transparent i.e. in a printout you won't be able to tell?

The comand Margaret told you about literally converts automatic numbering to
ordinary plain text. Having run that one line of code, there is no "magic"
left. (And, there's no going back, either!).

Your document will be exactly as if someone had typed the numbers by hand.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
R

Roscoe

Discovered a BIG drawback to this method...I have cross references to
paragraphs imbedded in the document e.g."see paragraph L-4 A". When I
do the "ActiveDocument.ConvertNumbersToText" routine, this becomes
"see paragraph 0".

Is there a way to convert all cross references to text as
well...first?

Thanks!

Roscoe
 
M

Margaret Aldis

Hi Roscoe

Yes, you can unlink or lock the fields. (Unlinking converts permanently to
text, locking offers the prospect of unlocking again later).

If you don't mind doing this on all the fields in the document, the one
liner

ActiveDocument.Fields.Unlink

(or ActiveDocument.Fields.Locked = True)

will do the job.

--
Margaret Aldis - Microsoft Word MVP
Syntagma partnership site: http://www.syntagma.co.uk


Roscoe said:
Discovered a BIG drawback to this method...I have cross references to
paragraphs imbedded in the document e.g."see paragraph L-4 A". When I
do the "ActiveDocument.ConvertNumbersToText" routine, this becomes
"see paragraph 0".

Is there a way to convert all cross references to text as
well...first?

Thanks!

Roscoe




The comand Margaret told you about literally converts automatic numbering to
ordinary plain text. Having run that one line of code, there is no "magic"
left. (And, there's no going back, either!).

Your document will be exactly as if someone had typed the numbers by hand.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


a
copy try
is 'now
how could
use to
find
[/QUOTE]
 
S

Stefan Blom

Alternatively, you can use the keyboard:

CTRL+SHIFT+F9 unlinks all fields in the current selection.

CTRL+F11 locks all fields in the current selection.

CTRL+SHIFT+F11 unlocks all fields in the current selection.

--
Stefan Blom


Margaret Aldis said:
Hi Roscoe

Yes, you can unlink or lock the fields. (Unlinking converts permanently to
text, locking offers the prospect of unlocking again later).

If you don't mind doing this on all the fields in the document, the one
liner

ActiveDocument.Fields.Unlink

(or ActiveDocument.Fields.Locked = True)

will do the job.
 
R

Roscoe

Great, I can add that to the other line in the macro and do both at
the same time. I suspect I have to lock the cross reference before I
convert the numbers to text :)

Thanks!

Roscoe
 

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