Macro to remove direct list number formatting without losing other formatting

J

Julie

I am writing some document cleanup macros and would like to remove directly
applied list numbering without losing paragraph and font formatting. Once
the direct numbering is removed, I want to copy the paragraphs to a new
empty document and paste as formatted WITHOUT the list templates being
copied to the new document.

It doesn't seem to suffice to remove the numbering
(activedocument.range.listFormat.ConvertNumberstoText). When the paragraphs
are copied to the new document, ALL of the list templates from the old
document are copied into the new document even though all of the paragraphs
are styled with Normal style and Normal style is not numbered and it is less
than the whole of the document being copied.

I want to leave the list templates behind. Is that possible, or is there no
alternative to pasting as unformatted text.

Word 2K fully patched, Windows XP.

Thanks in advance,
Julie
 
W

Word Heretic

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

One simple way would be to take everything from each para EXCEPT the
para mark, the para mark holds the LT reference.

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

steve from wordheretic.com (Email replies require payment)


Julie reckoned:
 
J

Julie

Hi Steve,

Thanks for the reply. The objective is to lose only the list template link,
and not any other formatting. I thought it was reasonable to expect that
the "ConvertNumbersToText" method would UNLINK the paragraphs from the list
template but that doesn't seem to happen. Correct? I take it by your
response that there are no Word VBA methods that can be used on the
paragraph to force the unlinking Correct? If I have to, I will track the
existing formatting, then extract the text to a new paragraph and restore
all of the formatting, property by property, but that is one heck of a lot
of work. Any better way?

Thanks,
Julie
 
B

Bruce Brown

Julie -
I am writing some document cleanup macros and would like to remove directly
applied list numbering without losing paragraph and font formatting.

Does "directly applied list numbering" mean 1,2,3 numbering from the
formatting toolbar?

If so, ironically, this kind of numbering does *not* create a new list
template after it has been converted to text in the source doc and
pasted in to the target doc (at least, not in Word 2002).

Select a list created this way, do a
Selection.Range.ListFormat.ConvertNumberstoText, copy the selection
and paste it in a new doc, checking the number of list templates in
the new doc before and after you paste. It remains the same.

What then does "directly applied list numbering" mean exactly? And is
there some special reason why you want to keep the list templates out
of the target doc? Would it be satisfactory if they were brought in
but then unlinked from their numbering styles afterwards?

The fact that your post didn't get any nibbles suggests that people
are skeptical about its doability. Frankly, I am too, but I thought
I'd ask some questions in case that triggers a solution in someone's
mind.

- Bruce
 
B

Bruce Brown

Did not see your last post when I posted.

If unlinking is what's called for, try this:

ActiveDocument.ConvertNumbersToText

Dim L As ListTemplate
For Each L In ActiveDocument.ListTemplates
On Error GoTo EndLoop
If L.ListLevels(1).LinkedStyle <> "" Then
Select Case L.OutlineNumbered
Case True
For k = 1 To 9
L.ListLevels(k).LinkedStyle = ""
Next
Case False
L.ListLevels(1).LinkedStyle = ""
End Select
End If
EndLoop:
Next

First step has to be converting numbers to text, otherwise unlinking
will make the numbers disappear.

Even then, when you have several outline numbered list templates in
one document, converting numbers to text will randomly remove numbers
from levels 1 and 2. Go figure.

Unlinking does not eliminate list templates. They have eternal life.
But it does send them to outer space where, in the opinion of many,
they came from in the first place.

- Bruce
 
J

Julie

Thanks Bruce,

I am using Word2000.
By list numbering directly applied, I mean that the paragraph is list
numbered but not through a numbered style. Because I didn't create these
dirty documents, I am assuming that the numbering was applied from the
toolbar buttons or directly thru the B&N dialogue.

I already have in the procedure code to unlink the styles from all outline
numbered list templates, and it doesn't make a difference in Word 2K. If
numbering was applied directly (from toolbar or B&N dialogue), I cannot seem
to shake the list templates when copying to the new document. Tomorrow, I
will try the process in Word 2002 and am betting that it is not a problem
with 2002, as you suggest. We may be upgrading anyway because of the
improvements for pasting numbered text among documents.

Some of the documents being cleaned have hundreds of list templates in them,
so I would prefer to leave the list templates behind as the objective is to
produce the healthiest document possible without losing all of the
formatting. I don't trust a document with that many list templates --
bitten too many times.

Before your post, I wasn't aware that .ConvertnumberstoText method can
result in loss of numbers. Thanks for that. When time permits, I will have
to reorganize the whole process to work around that, and that reorganization
will also work around the list template problem, but it will be time
consuming to write that because it will necessitate tracking all properties
for the paragraph, stripping all format from it, then restoring all
formatting - for all paragraphs with list numbering directly applied. Ugly.

Thanks very much.

Julie
 
J

Julie

Bruce,

I noticed in your code snippet something that I had overlooked - unlinking
the styles from the list templates that are NOT outline numbered. Thus, I
replaced my linked style unlinking procedure with your code and,
unfortunately, with Word2000 there is no difference.

You are right that this is not a problem with Word 2002. I just ran the same
macro (original with my code), with the same documents, same global
templates loaded, etc. in Word2002 and it worked as I designed it to - that
is sends those list templates into outer space forever (translation ... they
don't get copied to the new document when the text is copied).

That leaves me little hope for a resolution with Word 2000 and I think I
will stop spending time trying to make it happen.

I found a solution that will work for the majority of my problem documents
(simple in format, but lots of numbering): that is: compare the list
template count in the blank new document window with the count after the
paste and, if list templates were copied in with the paste, save the
document as HTML, reopen, save as Word doc. That invites some more problems
so I will probably restrict it to situations only where there are an
excessive number of list templates hanging around - maybe 100 more (which is
not uncommon in documents that come to me for cleanup).

Re your earlier post about .ConvertNumbersToText method resulting in loss of
some numbers, do you know what circumstance causes that? I am thinking that
if the circumstances are definable, maybe I can fix the list template before
converting the numbering to text.

Thanks a mil.
Julie
 
W

Word Heretic

G'day Julie & Bruce,

I do not have the time for a detailed discussion on the Word BFF and
its 'implementation' methods. Instead, I shall wax lyrically and
prosaically and inside this madness you will find some sanity.

Word is object based. It's legacy base was file format based. So we
have an essential conflict of interests. Word maintains document
chunks through the combining of many property tables, which are then
subsequently referred to in the actual binary structure.

So, we create a numbered list. Lets make it the worst possible way -
through the GUI using the ListGalleries (LG) collection. So we fiddle
up the settings and word changes some property tables for the
application settings. It then stamps these into the document and LINKS
our paras to the settings, based on the applied style for those of us
being smart, or the para's formatting table, for those of using direct
numbering :-(

So you convert the doc #'s to text. All this does is remove the
numbering at the front of the field. It has done nothing for the list
templates themselves, and I suspect a spurious reference being left
over purely for the purposes of programmatic undoing of this. Look at
the RTF file produced, if there are any .li bits instanced in your
styles it is still attached.

Similar ghost objects exist for footnotes, comments, bookmarks and the
like. There are various ways of overwriting these object's binary
reference inside the document rather than properly destroying the
object itself. This leads to orphaned footnotes & comments, crazy list
numbering and so on. The binary object still exists, just the
reference link to it is in less than perfect shape due to some
editing.

Even if we were to get rid of this spurious reference, we havent done
a damn thing about the list template definition stamped into the
document. It's waiting around for another reference to be made to it,
which is sensible. What is not sensibubble is MS providing NO means to
..Delete one of the suckers. Why? Well it's buried 10' deep in patches
from the original legacy StoneHand system. Its not 1 code fix, its 50.
Autoformat, render, enter key, tab keys at start of para etc etc.

I have a feeling it is congruent with Douglas Adams' (RIP) theory in
so far that should someone actually understand all of it at once, it
will automatically change into something mroe incomprehensible. As
proof this has already happened, I refer the gentle reader directly to
List Styles in Word XP+.


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

steve from wordheretic.com (Email replies require payment)


Julie reckoned:
 
C

Cindy M -WordMVP-

Hi Steve,
Instead, I shall wax lyrically and
prosaically and inside this madness you will find some sanity.
Interesting. Thanks for taking a moment to put all of this in
clear text :)

So... if one would save out to, say, the new Word 2003 XML and
clean any list stuff out of that, then bring it back into Word
and save as a doc - would that clean it up, in your opinion?

Cindy Meister
 
W

Word Heretic

G'day Cindy M -WordMVP- <[email protected]>,

Absolutely. The only other requirement might be to ensure it has a
template with no list templates in it, so that when it's recreated
they don't get stamped in.


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

steve from wordheretic.com (Email replies require payment)


Cindy M -WordMVP- reckoned:
 
J

Julie

Hi Steve,

Thank you for the info about the "ghost references". Now I see why I must
give up on this idea! For the sake of interest, I tried one more experiment
before so doing, that is:

.... took one of the problem documents (e.g., numbering had at one time been
directly applied to text) and removed all of the paragraph marks and tables
so that the document was one large paragraph. From there, selected the
whole document except the final (and only) paragraph mark and pasted it,
(formatted), into a new document with no list templates.

I was hoping that Word would link the "ghost references" to paragraph marks
(which would still leave me some room for a resolution to my problem), but
that did not hold true in that experiment, Without including any paragraph
marks in the selection, all 108 list templates were still copied to the new
document. I will stick with the HTML save for the time being until we
upgrade away from Word 2K.

Thanks very much for your help.

Regards,
Julie
 
W

Word Heretic

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

<Giggles>

Nice try Julie, but every time you deleted a mark whatever it carried
just hopped over to the next mark - and you always have one such mark
per document if for no other reason than to carry this stuff :)

What you need to do is select text upto but not including the para
mark and copy it into a new doc and add the para mark there :)

<Still chuckling>

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

steve from wordheretic.com (Email replies require payment)


Julie reckoned:
 
J

Julie

Hi Steve,

I did exclude the paragraph mark from the copy (maybe that was not clear my
post "...except the final (and only)...paragraph mark...)" and the list
templates still came over without the selection containing any paragraph
marks. Any more ideas?

Julie
 
B

Bruce Brown

Julie -

Before pasting to a new doc, have you tried selecting the lists in the
"dirty" doc and applying one of the built-in List Number styles to
them? That does not create a new list template in either the source
doc or the target doc because the List Number styles are already
linked to an existing list template by default in both docs.

Also, are you working with hundreds and hundreds of docs with this
problem or just a few? If it's hundreds then any solution will have to
be automated, and suggestions like the above would be unfeasible on a
large scale.

- Bruce
 
J

Julie

Hi Bruce,

Applying another style won't solve my problem because I wish to keep all
font and paragraph formatting except the link to the list template. I need
that font and paragraph formatting so that, after the initial
conversion/cleanup, the user can run a re-styling tool that will guide the
user to selection of the correct corporate style according to the existing
paragraph and font properties.

I think it's time to thow in the towel. There doesn't seem to be a way to
get around the ghost reference problem described by Steve.

To satisfy myself that there is likely no way to work around the ghost
reference problem (and keep formatting without doing the HTML save), I tried
this:

1. in the source document, added a few padding paragraph marks at the
bottom.
2. Selected and cut the whole document except the padding paragraph marks
and pasted it back into the source document, as unformatted text.
3. Cleared the clipboard then selected the unformatted text excluding any
of the padding paragraph marks at the bottom.
4. Pasted that text into a new document as formatted text
.....
and to no surprise, all of the list templates came along with it, in this
case 216 of them. I'm convinced to throw in the towel. There doesn't seem
to be a way to lose the ghost references by manipulating the document
objects with VBA.

As for number of documents afflicted, the problem arises often (daily) and
it's an on-going problem. We regularly share numbered legal documents with
the outside world. Likely, that says it all.

Thanks very much for your interest in this problem,

Julie
 
W

Word Heretic

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

Unfortunately the full solution is in some unfinished commercial code
of mine :-(

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

steve from wordheretic.com (Email replies require payment)


Julie reckoned:
 

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