PDA

View Full Version : Modifying Styles



Bert
05-02-2011, 12:03 AM
Hi All,

I am wanting to define how i want heading 1, 2 and 3 and then apply these to the already defined headings in the document.

I am currently using the following:

With ActiveDocument.Styles("Heading 2")
.Font.Name = "Times New Roman"
.Font.Size = 12
.ParagraphFormat.SpaceAfter = 2
.ParagraphFormat.SpaceBefore = 24

End With

This will only effect the first heading, and I want it to work on all the headings in the document of each type.

Any help would be greatly appreciated.

macropod
05-02-2011, 01:06 AM
Hi Bert,

If you modify the Heading 2 Style, then every paragraph in the document based on that Style will be updated - immediately.

Bert
05-02-2011, 01:10 AM
I am aware that this is meant to work... but for some reason when i run this code i get the following:

Heading 1
- The first one updates to the new defined style

Heading 2
- All update to the new style

Heading 3
- The first updates to the new style

This is why I am frustrated, its a simple process that isn't working and I am not sure why...

macropod
05-02-2011, 02:10 AM
Are you sure the ones that aren't updating are actually in the Heading 3 style - and not another Style that just looks like it? Also, if someone has applied hard-formatting to paragraphs based on the Heading 3 Style, that might explain why they are not updating correctly.

Frosty
05-02-2011, 08:40 AM
Depending on what version of Word you're using, there are some bugs related to styles, which can cause style formatting to become direct formatting. There is a large variety of factors, and not really worth exploring if you're just looking for a "one-off" type solution.

Try going to one of the paragraphs which isn't being affected by your macro and re-applying Heading 3... does it work then?

Bert
05-02-2011, 08:51 PM
Thanks guys, feeling like a bit of a fool now... the problem was different people added the headings, some used the defined styles, others edited the style and others didnt even use the styles...

Works well now they are all standard styles.

Thanks again.