PDA

View Full Version : Formatting the Style using VBA in MS word



balasvpr
09-28-2008, 01:52 PM
Hi all,

MS word have a option to add the Style Format with the already existing style i.e can able to add numbering or bullets with styles.

For example : i can able to add the numbering to the Heading1 style . Whenever i use the formatted style text will display with number and heading1. To do this in Msword .. click Style -> Format -> Numbering:help

Is there any way to do with VBA ?

Please tell me if there any examples or where i can find the VBA code for the same.

Thanks

Nelviticus
09-29-2008, 01:44 AM
Have a look at Document.Styles in the VBA help. Ranges have a Style property so you could do something like:
Selection.Range.Style = ActiveDocument.Styles(wdStyleHeading1)
For bullets and numbering you can use a Range's ListFormat property. There are lots of ways of doing this (look up Range.ListFormat in the VBA help) but a simple one would be:
Selection.Range.ListFormat.ApplyBulletDefault
Regards

balasvpr
09-29-2008, 03:36 AM
Its working fine.

Thanks for your response

balasvpr
10-01-2008, 03:08 AM
In MSword 2003 i have added the paragraph and numbered the paragraph using
Selection.Range.ListFormat.ApplyNumberDefault.
It displayed the text in MSword like this
1. Section1
2. Section2
3. Section3
4. Section4
Now i want to add some more paragraphs in already avaiable document and continue the number from the list
Ex
1. Section1
2. Section2
3. Section3
4. Section4
5. Section5
6. Section6
7. Section7
Please let me how to i do i get the last added paragraph number and continue the number from previous list.

Please let know if i can found the example for the same anywhere