Question : With VBA and Word, how can I change a paragraph style without affecting character styles in that paragraph?

Using VBA in Word, I need to apply a new style to a paragraph of text, some of which is in italics. That kills the italics.

In detail, I use the command
     ActiveDocument.Paragraphs(1).Range.Style = "Different Style"
Where Different Style is the new paragraph style.
      Unfortunately that removes all character formatting in the paragraph.

To overcome that at least for italics, I
1.      Find two character that I call ItalicsStart and ItalicsEnd, characters are not already in the document
2.      I put the first character at the start of each italicized section and put the second character at the end of each such section.
3.      I reset the style of the paragraph with the command shown above
4.      I then reitalicize the text:
     a.      I search for the first ItalicsStart character.
     b.      I delete the character.
     c.      I turn on extend and search for the ItalicsEnd character.
     d.      I italicize the selected text.
     e.      I collapse to the end and delete the ItalicsEnd character.
     f.      I repeat the above steps until there are no more places where I need to italicize the text.

Those steps do not handle anything in bold or underlined but at least they work for italics, and it hardly seems worth the trouble to do the same for bold or underlined text. Is there not something else I could do to keep the character formatting as I change the paragraph style?

Answer : With VBA and Word, how can I change a paragraph style without affecting character styles in that paragraph?

Response to Graham Skan: I searched MS Word help, Herb Tyson's Word 2007 Bible, and I Googled "vba word linked styles". Nothing helped with my particular problem.
     Since then, I found a solution:
       a. Specify a new character style named "Italics" or whatever name you want. Define its formatting as italics.
      b. Instead of simply selecting text and pressing Ctrl + I to italicize the selected text, apply the new style to the selection. You can have VBA do that too, as long as you have previously created the character style.
      c. When you then apply a new paragraph style to the paragraph, it retains the character styles in the paragraph.

     The only problem I see with that solution is how can one make a new character style in MS Word 2007? It has a bug (a feature?) that will not let you make a new character style in the Apply Styles window where you normally make new paragraph styles. (The character style choice is deactivated.) Instead, to make a new character style, you have to go to the Home tab and in the "Styles" section, you click on the little button in the lower right corner.
     That opens the "Styles" window at the bottom of which are three buttons. The leftmost of those three buttons is the "New Style" button. If you click on that, you see the same dialog box you see in the Apply Styles window, but here the character style choice is no longer deactivated.
           Thanks to you and JOrzech for your help. Without your comments, I probably would not have found the solution.
                 --j.r.a.
Random Solutions  
 
programming4us programming4us