格式从字符或单词到行末尾的文本

发布于 2025-02-01 14:38:41 字数 683 浏览 4 评论 0原文

下面的代码找到文本“ //”,并用绿色格式化整个线。

我正在尝试对其进行修改,以便它仅从文本“ //”到线的末尾进行格式。 ”

包括

//

Sub FindWord_and_ChangeColor()

    Dim LastRow, i As Long
    
    Selection.HomeKey Unit:=wdStory
    
    With Selection.Find
        .ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Text = "//"
        .Execute
    End With
    
    Do While Selection.Find.Found
        Selection.Expand Unit:=wdSentence
        Selection.Font.Color = RGB(107, 187, 117)
        Selection.Collapse Direction:=wdCollapseEnd
        Selection.Find.Execute
    Loop
End Sub

。查看我是否可以在自动生成的代码中找到解决方案。但是,我感谢任何可以帮助我的人。

The code below finds the text "//" and formats the entire line with green color.

I'm trying to modify it so that it's only formatted from the text "//" to the end of the line. (including "//")

So instead of this result:

example text //color changed

I aim to achieve this:

example text //color changed

Sub FindWord_and_ChangeColor()

    Dim LastRow, i As Long
    
    Selection.HomeKey Unit:=wdStory
    
    With Selection.Find
        .ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Text = "//"
        .Execute
    End With
    
    Do While Selection.Find.Found
        Selection.Expand Unit:=wdSentence
        Selection.Font.Color = RGB(107, 187, 117)
        Selection.Collapse Direction:=wdCollapseEnd
        Selection.Find.Execute
    Loop
End Sub

I'm recording macros to see if I can find a solution in the auto-generated code. But I thank in advance to anyone who can help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-02-08 14:38:41

更改

选择。expand单元:= wdsentence

to

selection.moveend单位:= wdsentence,count:= 1

Change

Selection.Expand Unit:=wdSentence

to

Selection.MoveEnd Unit:=wdSentence, Count:=1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文