Best practice re list templates?

C

Chuck

Hi all

I'd really appreciate some best practice advice re using VBA for setting up
list templates and styles for outline/paragraph numbering. We're getting
ready for a major format/style conversion and I'd like to make sure we get
paragraph numbering right.

We're staying with Word 2000 for the time being but working with documents
that were originally created in Word 2000 as well as WordPerfect (a variety
of versions) and Word 97.

We have a master "Normal" template with the new formatting and new styles.
I've developed a macro that uses .UpdateStyles (3 times) to try to update the
styles in the documents to be converted. Unfortunately .UpdateStyles (x3)
doesn't seem to update outline numbering on relevant styles reliably or
correctly. I've tried using .OrganizerCopy and that seems to do a better job
but even that doesn't seem to get the outline numbering right -- sometimes it
copies the outline linking correctly sometimes it doesn't and there doesn't
seem to be any particular pattern: it will get certain styles right in one
document but not in the next. (I don't know if that's a problem with lurking
legacy incompatibilities in the documents or what.)

I'm thinking that the only way to make sure that outline numbering and
linked styles in the styles in the converted documents are uniform and match
the styles in the new Normal template is to do it through VBA, by setting up
a macro (or series of macros) that define each and every style. Is that a
good idea or is there another way to do it?

BTW here's the code I've been using to try to get the styles copied over
just in case anyone can see something wrong in what I've been doing.

Thanks in advance for any advice! Chuck

Sub UpdateStyles()

Dim oLT As ListTemplate
Dim oStyle As Style
Dim sLKStyle As Variant
Dim i As Integer
Dim sStyleTemplate As String

On Error GoTo errorhandler

sStyleTemplate = "C:\Program Files\Microsoft
Office\Templates\NewNormal.dot"

With ActiveDocument
.AttachedTemplate = sStyleTemplate
.UpdateStyles
.UpdateStyles
.UpdateStyles
End With

For i = 1 To 5
Application.OrganizerCopy _
Source:=sStyleTemplate, _
Destination:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="Level " & i, _
Object:=wdOrganizerObjectStyles
Next i

For i = 1 To 5
Application.OrganizerCopy _
Source:=sStyleTemplate, _
Destination:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="NA - LEVEL " & i, _
Object:=wdOrganizerObjectStyles
Next i

'And so on, going through a number of different
'defined style/numbering hierarchies

'Relink levels to styles
Set oLT = ActiveDocument.Styles("Level 1").ListTemplate
For i = 1 To 5
sLKStyle = "Level " & i
oLT.ListLevels(i).LinkedStyle = sLKStyle
Next i

Set oLT = ActiveDocument.Styles("NA - LEVEL 1").ListTemplate
For i = 1 To 5
sLKStyle = "NA - LEVEL " & i
oLT.ListLevels(i).LinkedStyle = sLKStyle
Next i

'And so on, re-linking each number level to its LinkedStyle

MsgBox "Styles in this document have been updated.", _
vbOKOnly + vbInformation, "Styles Updated"

Exit Sub

errorhandler:

Select Case Err.Number

Case 91
MsgBox "Check " & sLKStyle & " to make sure " & _
"numbering and linked styles are correct.", _
vbExclamation + vbOKOnly, _
"Problem with numbering styles encountered"

Case Else
MsgBox Err.Number & " " & Err.Description

End Select

Resume Next
'Exit Sub

End Sub
 
M

Malcolm Smith

Chuck

The first and foremost thing is that I wouldn't put anything into
Normal.dot at all. I would built all the styles on ONE machine with ONE
user account and place them all into each document template.

That is the least worst way of doing them. Putting the styles into Normal
is asking for trouble as Normal.dot will be killed from time to time. In
fact don't put anything into Normal.dot if you can help it.

Doing this would solve 99% of any future problems.

- Malc
www.dragondrop.com
 
C

Chuck

Hi Malcolm

Thanks for the tip, sounds prudent. Meantime, my most pressing problem is
getting the documents (not the templates) to number correctly using the
appropriate outline numbering and linked styles after updating, which doesn't
seem to be happening reliably. Any ideas (from anyone?) on whether it's best
to use code to redefine the styles from scratch in each document or will that
cause even more problems?

Chuck
 
W

Word Heretic

G'day "Chuck" <[email protected]>,

If you write some List Template / List STyle setting macros, then yes,
you can trigger them anytime to set up any document. However, a more
user-centric manner is to create one nice template with well behaved
list definitions it, then to add them to an existing document use File
New > Your clean template and coppienpaste the old doc in, save over
the top.


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Chuck reckoned:
 
C

Chuck

Hi Steve

I've tried the copy and paste, but the style formatting (indenting mostly)
gets screwed up somehow -- the indents are set properly in in both the old
and new docs' styles, but when I paste "old" into "new" the indents go all
over the place. Whatever solution I come up with has to be automatic and
relatively foolproof/troublefree to accommodate non-technical users
converting their documents to the new formats on an as-needed basis.

I've been researching the goolge groups archives and it seems that paragraph
numbering / list templates are a major pain and I'm getting the feeling that
I'm going to have to go ahead and code the macros to redefine the styles and
listlevels programmatically. Argh. The tedium.

Chuck
 
S

Shauna Kelly

Hi Chuck

Copying and pasting bulleted and numbered text frequently doesn't work,
whether done in the user interface or in code.
I'm getting the feeling that
I'm going to have to go ahead and code the macros to redefine the styles
and
listlevels programmatically.

Yes. For what it's worth, in cases like this, I get the code to re-create
all bulleting and numbering settings every time the document is opened.

There are two big rules:
1. Link your style to a list level of a list template. For example:
oMyListTemplate.ListLevels(1).LinkedStyle =
ActiveDocument.Styles(wdStyleHeading1).NameLocal

and

2. Manipulate the ListLevel to get the formatting (eg indenting) that you
need. For example:
oMyListTemplate.ListLevels(1).NumberPosition = CentimetersToPoints(1.5)

Hope this helps.

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

Chuck

Thanks Shauna. By coding the list templates I guess I'll "know" that it's
right.

Question: Is there a way to delete existing (named) list templates? I saw
references in the google groups archives to "eliminating" existing named list
templates by setting their names to "" (zero length string) but that's not
the same as deleting them -- there were posts mentioning documents with 1000+
(unnamed) list templates which had become unstable. The only solution I saw
listed in google groups was to copy/paste from old doc to new doc, paragraph
by paragraph (leaving out the paragraph markers) to leave behind the phantom
list templates, which is out of the question as a solution for us (we don't
have the people or time resources for that sort of thing).

Thanks again. Chuck
 
S

Shauna Kelly

Hi Chuck

No, you can't delete a list template <***sigh***>. Word 2000 used to fall
over when a limit was reached (I can't now remember what the limit was).
Word 2002 and Word 2003 will, eventually, delete unused ListTemplates if a
document nears the limit. At least that's what's supposed to happen; the
only way to really test it would be to get a whole lot of user-created
documents and examine them. But I haven't run into problems with this in
2002 or 2003.

You can sometimes copy great chunks of text (generally, excluding section
marks) from one document to another and leave behind unused list templates.
But it needs to be Friday 29 February, with a full moon, and you need
several black cats available to make it reliable.

For what it's worth, I try to manage this issue as follows:

1. Create a template by doing File > New and and in the FileNew dialog box,
click the Template radio button. That is, don't start with a copy of an
existing template, or use File > Save As to turn a document into a template.
Creating a template by doing File > New ensures that you create a clean
template. For what it's worth, a clean template is *not* based on
normal.dot. It's generated by the Word executable with all Word's defaults.

2. Do everything you can (eg set up styles and ListTemplates) in code, so
that, in development, you can create a new template and replicate it at
will.

3. Teach users to create a new file by doing File > New. Obviously creating
a new document by opening an old one and doing File > Save As can lead to
cumulative problems.


Hope this helps.

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

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