PDA

View Full Version : Word VBA Paragraph formatting



senthilkumar
02-16-2009, 06:31 AM
Hi All,

I am using word VBA. I have created my own styles. The document we are working will have formats such as bold, italic, underline, subscript, superscript etc,. While applying my styles in the author document, existing formats are getting changed. I want to retain all the existing formats while applying styles. Is it possible???

Ex:

In this chapter, we will look at the simplest form of constitutive equa-tions for fluids having no viscous stress. To expand our range of applica-tions further, we will then extend the concept of invicid flow to include po-tential flow and unidirectional incompressible flow.


Thanks,
Senthil.:banghead:

fumei
02-16-2009, 10:27 AM
"I want to retain all the existing formats while applying styles. Is it possible???"

No. This is a total contradiction. If you apply the styles...the format of the styles apply. That is what styles are for, applying format. WHY would you apply a style but keep the original formatting?

It is possible you need to look up the use of character styles. They are different from paragraph styles.

senthilkumar
02-16-2009, 10:08 PM
Hi fumei,
I mean that the para I want to apply styles has already having some formats such as bold, italic, underline etc., for sprecific words and not for entire para. While applying my style these things have to be retained.

Thanks,
Senthil.:banghead:

TrippyTom
02-16-2009, 10:55 PM
yes, that would be character styles.

Here's some links that might help clear up your confusion:
Understanding paragraph, character, list, and table styles (http://office.microsoft.com/en-us/word/HA011876141033.aspx)

Word's Character Styles (http://pubs.logicalexpressions.com/pub0009/LPMArticle.asp?ID=684)

fumei
02-17-2009, 12:07 PM
Good links Tom.

senthilkumar, essentially the answer to your question is, again, no. It is not possible, or at least not without a fair amount of VBA coding to parse through each word to find out its attributes.

The problem is - as it always is - the underline, bold etc. done in your text was manually formatted. People selecting words and clicking that darn Bold button, or Underline button.

That is manual formatting, and will always mess up doing things.

If I had my way, I would (and DO in my documents) remove all manual formatting buttons from Word. I never, ever, do any manual formatting.

"While applying my style these things have to be retained."

If they have to be retained, then it is NOT your style.

It is possible, but as I stated, you would have to:

1. create the appropriate Character styles;
2. parse through each word checking its current attribute;
3. if its current attribute is NOT the same as your paragraph style, store what that attribute is, clear that attribute, and then apply your own appropriate character style.