How programatically set text styling in ms word?

后端 未结 1 921
攒了一身酷
攒了一身酷 2021-01-26 16:05

Situation:
I\'m working with MS Word document\'s contents. I\'m changing color of some words according to some rule. Words coloring occurs on each KeyPress event.

P

相关标签:
1条回答
  • To set default color you have two options:

    //really default color:
    r.Font.ColorIndex = Word.WdColorIndex.wdAuto;
    
    //assuming default is black- set it to black
    r.Font.ColorIndex = Word.WdColorIndex.wdBlack;
    

    Edit. To set the color back to default as of selected range you could try this code:

    Word.Application.Selection.Font.ColorIndex = Word.WdColorIndex.wdAuto;
    

    It doesn't refer to active document but to Selection of the application. After you run it next words are written in default color.

    0 讨论(0)
提交回复
热议问题