PDA

View Full Version : Get a List Template from a paragraph



silversurfer
09-01-2011, 05:48 AM
Is there any way in which it is possible to retrieve a paragraph from a document and determine exactly which list template it has applied to it, i.e the gallery type and list template within that gallery. For example if I wanted to apply a standard bullet I would select gallery one, list template one, but I want to work backwords in the other direction, only I don't know how to do this.

Alternatively, another solution to my problem would be if there's any way to tell word that when bullets are applied (manually by the user, using the drop down menu) I don't want it to set the name to be "", which it appears to do be default.

Regards and thanks for any help.

Frosty
09-01-2011, 11:35 AM
The first thing to understand is that the gallery positions and the actual listtemplates have almost nothing to do with each other. More reading on this subject can be had here (and if you're going to dive into this particular area of Word via programming, I highly recommend reading and understanding the link).

It's import to know that recorded macros with numbering will get you into far more trouble than other areas of word (where recording the macro can be useful to learn about particular classes/methods/properties).

EDIT: changed the link slightly
http://word.mvps.org/faqs/numbering/WordsNumberingExplained.htm

Other than that... can you describe the problem a little more fully? Word sets the name of any automatically created ListTemplates to a blank name (which is one of the many problems with Word numbering).

This topic (at least from the front end--that link, while old, is still very accurate as to what is going on behind the scenes) is also highly dependent on which version of Word you're using.

The only way to interrupt the manual application of bullets on to text (i.e., direct formatting) is to either a) commandeer the actual bullets button with your own button, and apply a style with bullet formatting or b) train your users to use styles.

There are a *lot* of gotchas in Word numbering, and you will ultimately be disatisified with a purely code-based solution (i.e., no end-user training).

Or, in short, if there were a short answer to your question-- Microsoft's numbering wouldn't be so tricky to explain.

silversurfer
09-02-2011, 12:57 AM
The problem is that essentially I'm trying to programmatically copy any paragraph formatting which has been applied to one document, and apply it to another in exactly the same way. This isn't too difficult to do with a basic bullet, but if they choose anything else from the bullet list then there doesn't seem to be any way to distinguish this from the standard bullet. From what you're saying and the link you provided it looks like numbering will prove to be even more complex also. Unfortunately end-user training isn't really an option, though I suppose replacing with our own button might be in the long-term, though not currently. It seems that word doesn't provide a lot of options for dealing with this programmatically, and it may have to be limited to the most basic functionality possible.

Frosty
09-02-2011, 09:25 AM
I don't know what do you mean when you say "programmatically copy any paragraph formatting which as been applied to one document, and apply it to another in exactly the same way."

How would you do this? If the words aren't the same, how do you know paragraph 2 from one document should have the same formatting as Paragraph 4 of another document? Style name? Other bits of formatting? No matter what the process, you still need to have some kind of identifier so that your program can make decisions. Obviously you want to change something... but how do you know what you want to change, and to what you want to change it?

Programmatically, it's all exposed (caveat, I can't immediately figure out how to retrieve the .NumberFormat specifically for a bullet character, even though I know what the value should be -- so I can test to see if it equals ChrW(61623) and return true, but I can't seem to retrieve the equivalent value-- worst case scenario here, you would simply have to come up with a list of values to test against if you weren't able to retrieve it)

But other than that, you just have to understand it in order to really manipulate it. If you're not familiar with using the watch windows, it becomes tricky, but you want to get to know the ListTemplate and ListFormat objects, and then check them out in the Locals Window when using the following macro. That will begin to show you some of the behind the scenes complexity. It will help to have a 3 pararaph document, with bulleting applied to the first paragraph... then you can see a basic premise (using the Stop to check out the locals window before you apply the list template to the 3rd paragraph).

Sub TestBulletCopy()
Dim oLT As ListTemplate
Dim oLF As ListFormat

Set oLT = Selection.Paragraphs(1).Range.ListFormat.ListTemplate
Set oLF = oLT.Parent
Stop
ActiveDocument.Paragraphs(3).Range.ListFormat.ApplyListTemplate oLT
End Sub

Before moving on from the Stop... look at the locals window and expand both the oLT and oLF objects, and you can start to see all the various bits of formatting which may be helpful to identify.

I retract my statement that the recorded macros aren't helpful... they are, since you can get some basic values from them. As long as you ignore the ListGalleries object (which will look like it's the most important repository of ListTemplates-- it isn't).

However-- if all you want to do is copy formatting... you could use Format Painter to do that, and forget the whole "understanding numbering" thing.

If you're attempting to do something analagous to copying "styles" (in the form of list templates) from one document to another (and replace them) so that those list templates are simply available for a human to later apply, then there's going to be a bit more work involved... and you haven't said what version you're working with (which will matter-- as will the format of the files you're working with (.doc/.docx in compatibility mode/.docx not in compatibility mode).

It's all possible, programmatically, it just depends on your threshold for learning it and what you really need.

If you continue to respond and refine what you need... you may find that you don't actually need to understand the depths of Word numbering in order to do what you want.

So... let's start with what you want to have happen:
1. You want (some) paragraphs in DocumentA to look exactly like they do in DocumentB Do you want a human or a computer to decide which paragraphs to grab formatting from and apply formatting to?

2. Is the document you're copying the formatting from always going to be the same (i.e., is it a "template" or is it just another document)?

silversurfer
09-02-2011, 09:28 AM
I don't know what do you mean when you say "programmatically copy any paragraph formatting which as been applied to one document, and apply it to another in exactly the same way."

How would you do this? If the words aren't the same, how do you know paragraph 2 from one document should have the same formatting as Paragraph 4 of another document? Style name? Other bits of formatting? No matter what the process, you still need to have some kind of identifier so that your program can make decisions. Obviously you want to change something... but how do you know what you want to change, and to what you want to change it?

Programmatically, it's all exposed (caveat, I can't immediately figure out how to retrieve the .NumberFormat specifically for a bullet character, even though I know what the value should be -- so I can test to see if it equals ChrW(61623) and return true, but I can't seem to retrieve the equivalent value-- worst case scenario here, you would simply have to come up with a list of values to test against if you weren't able to retrieve it)

But other than that, you just have to understand it in order to really manipulate it. If you're not familiar with using the watch windows, it becomes tricky, but you want to get to know the ListTemplate and ListFormat objects, and then check them out in the Locals Window when using the following macro. That will begin to show you some of the behind the scenes complexity. It will help to have a 3 pararaph document, with bulleting applied to the first paragraph... then you can see a basic premise (using the Stop to check out the locals window before you apply the list template to the 3rd paragraph).

Sub TestBulletCopy()
Dim oLT As ListTemplate
Dim oLF As ListFormat

Set oLT = Selection.Paragraphs(1).Range.ListFormat.ListTemplate
Set oLF = oLT.Parent
Stop
ActiveDocument.Paragraphs(3).Range.ListFormat.ApplyListTemplate oLT
End Sub

Before moving on from the Stop... look at the locals window and expand both the oLT and oLF objects, and you can start to see all the various bits of formatting which may be helpful to identify.

I retract my statement that the recorded macros aren't helpful... they are, since you can get some basic values from them. As long as you ignore the ListGalleries object (which will look like it's the most important repository of ListTemplates-- it isn't).

However-- if all you want to do is copy formatting... you could use Format Painter to do that, and forget the whole "understanding numbering" thing.

If you're attempting to do something analagous to copying "styles" (in the form of list templates) from one document to another (and replace them) so that those list templates are simply available for a human to later apply, then there's going to be a bit more work involved... and you haven't said what version you're working with (which will matter-- as will the format of the files you're working with (.doc/.docx in compatibility mode/.docx not in compatibility mode).

It's all possible, programmatically, it just depends on your threshold for learning it and what you really need.

If you continue to respond and refine what you need... you may find that you don't actually need to understand the depths of Word numbering in order to do what you want.

So... let's start with what you want to have happen:
1. You want (some) paragraphs in DocumentA to look exactly like they do in DocumentB Do you want a human or a computer to decide which paragraphs to grab formatting from and apply formatting to?

2. Is the document you're copying the formatting from always going to be the same (i.e., is it a "template" or is it just another document)?

silversurfer
09-02-2011, 09:35 AM
We have two documents which are linked in such a way that whatever changes a user makes in one are then converted into the form of an operation specifying what actions word needs to take to get the document to that state, and published across a network to another document belonging to another user, which then carries out those ops in order to have their document be exactly the same. So paragraph 1 in one document should be exactly the same as paragraph 1 in the other, and so on. If user 1 applies bullets to their first paragraph, the same type of bullet should be applied to the same paragraph in user 2's document.

The two documents themselves have no communication with one another. I'm not aware of format painter but having just given it a quick look I don't know if it would suffice because of the way in which we are registering changes to the initial document. There is no human input involved in any of this process, aside from changes they may be making to their own document. It also needs to be able to function cross-version, from 2003 onwards.

I hope that addresses some of your questions, if there's anything else you want to know just ask and I'll do my best to explain. Greatly appreciate the help so far.

Frosty
09-02-2011, 10:35 AM
Sorry, it's a bit nebulous for me to give you a concrete answer on... "linked in such a way that whatever changes a user makes in one are then converted into another document" ... so, you've programmed Word (on both ends) to essentially have a living mirror of one document to the other without any sort of real-time exchange by the actual applications?

I can't really give you any sort of concrete answer above what I've already done without some sort of rudimentary understanding of how you're even performing that mirroring process, quite honestly. How are you exchanging the info?

I gave you information assuming you knew nothing-to-not-much. Your reply is describing a process I'm having a hard time wrapping my head around (i.e., someone types a word... and it appears in the "other" document... someone makes a word bold and it becomes bold in the "other" document, and yet there is no ability for WordA (which is working on DocumentA) to connect to DocumentB currently in use by WordB?

So you have an intermediary "rosetta stone" spitting out and sucking up the textual and formatting changes? (i.e., WordA makes a list of changes in DocumentA, compiles a list, places it in some sort of DMZ, and WordB keeps checking that list and crossing off action items as it performs them?). And you need it to work in Word 2003 as well? Blech.

It seems overly complicated when you could simply set up a Wiki site which would essentially perform much of the same functions. I'd question using Word for this process at all. Much easier, conceptually, to "host" a web-page (a la a Wiki page) with multi-user editting capabilities, and then spit the content out as a Word document.

If you're having problems with bullets, just wait until DocumentA gets a TOC inserted, or a text box, or a picture... you're essentially describing a process in which you want to (potentially) have a 3rd party intermediary list out all of the actions Word has performed? It sounds like you're re-building Word. Are you trying to reverse engineer some aspect of it?

In any event... you're going to, essentially, need to list out all of the properties you care about in either or both the ListFormat object and the ListTemplate object. Hand those properties to your intermediary, and then affect those properties. Forget the ListGallery object (i.e., you can't just say "userA just applied ListGallery position 1, apply ListGallery postition 1 in DocumentB" -- you're going to need to get granular).

HOWEVER-- the big issue here (well, one of the many) is that you will eventually collapse these documents under the "weight" of their own list templates. You can't just forever create ListTemplates and apply them to text on the fly. Because Word has no mechanism for deleting them. So your documents will continue to bloat until they become corrupt. Especially if you are using the binary format (the xml format has a way of discarding confusing stuff whereas the binary format holds on to it).

I have no idea where you're at in this process... but I assume this isn't entirely vapor-ware. That you're trying to do this with direct-formatting is concerning, as you have not restricted the user input choices at all. That means your translator "pipe" needs to be able to, potentially, describe every formatting possibility Word can perform. On its face, this little issue you're having with bullets seems minor by comparison with the potential scope (and problems) in this process.

Frosty
09-02-2011, 10:46 AM
In short... what do you need from a website like this? Above a general point in the right direction "use list templates and list formats" -- what else would you need? You must already have at least one capable programmer if you've even started this process.

Unless this is one of those "scope creep" type things where you said "sure, we can program two documents in different offices to mirror each other real-time" and got stuck once you got past "synching" the text and basic bold/italic/underline type formatting.

silversurfer
09-05-2011, 06:12 AM
haha no I'm not just someone who's committed to something and now doesn't know how to get it done. Essentially I needed to know just how feasible it is to do what I've described and the potential issues involved. If necessary we can simply mark bullets etc as 'unsupported features', if they're going to cause too much trouble. At the moment we have the default function working for bullets and numbered lists I.e the basic bullet and numbered list, just by registering the change in listType . What I wanted to know was whether it was feasible to expand beyond this point by somehow gaining access to the specific types of list within each grouping, which I gather from what you have said will be very difficult to do, and presents potential issues with creating templates that can't be deleted.

We do have several very competent programmers but none who really have more experience in this particular area than myself

Frosty
09-06-2011, 10:33 AM
If you're the most experienced, then I'd start by reading the links above so that you can understand what's going on in the background. And then, generally speaking, attempt to modify existing list-templates between the two documents as you can, rather than simply allowing Word to create a new one for you on the fly.

Commandeering the process behind the scenes will pay dividends over the long haul, because then you can give each list template an actual name (which will allow you to identify changes in a list template, rather than attempt to identify the unnamed list template and then apply it). It will also allow you to limit the amount of list templates in a document (although Word will technically allow 100s of list templates in a document, even the most complicated document probably wouldn't even need more than 10).

Conceptually, the "big" issue here is that there are so many ways to "break" numbering (including bullets) in Word, that you have to decide what you want to do when UserA causes a "break" to the numbering: do you want to propagate that change to DocumentB... or do you want to "fix" the issue in DocumentA before doing performing the synch process?

I would also hazard a guess that if you think you've got list numbering working, but are having problems with bullets... you probably don't really have list numbering working like you think you do.

Understanding the various ways the typical end-user can break numbering (and why the industry-standard is to typically apply numbering through the use of a style with the numbering linked to it) will go a long ways towards helping you limit how often it breaks.

Hope this conversation has helped, and good luck!