简体   繁体   English

如何在不改变段落的整个样式的情况下设置单词的样式?

[英]How to set the style for a word without changing the entire style of the paragraph?

I am trying to make a macro which changes the style of all words in the document one by one, depending on the their current style, as in the actual style name and the font size and name. 我正在尝试创建一个宏,它会逐个更改文档中所有单词的样式,具体取决于它们当前的样式,如实际样式名称和字体大小和名称。

My problem is that, when I change the style of the very first word, it then changes the style of entire paragraph, which is very much not intended. 我的问题是,当我改变第一个单词的样式时,它会改变整个段落的样式,这是非常没有意图的。

'Loop trough all words
For Each w In p.Range.Words
...

...

'Switch based on the style of the word
Select Case r
    Case "b"
        w.Style = ActiveDocument.Styles("NewStyleB")
      ...

The property .CharacterStyle is readonly, however when I use the code below, only the word gets the style applied, as it should, it does however not keep the style in its style property or its character style property, which is quite important, so I am at a loss about what to do. 属性.CharacterStyle是readonly,但是当我使用下面的代码时,只有单词获得应用的样式,因为它应该,但它不会将样式保留在其样式属性或其字符样式属性中,这非常重要,因此我不知道该怎么做。

'Loop trough all words
For Each w In p.Range.Words
...

...

'Switch based on the style of the word
Select Case r
    Case "b"
        w.CharacterStyle = ActiveDocument.Styles("NewStyleB")
      ...

Word has few style types . Word几乎没有样式类型 Check if your style is a paragraph style, and if it is then you can copy it to a new style and change it to a character style. 检查您的样式是否为段落样式,如果是,则可以将其复制到新样式并将其更改为字符样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM