将 MS Word 文档中每个句子的第一个字母加粗

发布于 2024-09-06 18:59:02 字数 50 浏览 2 评论 0原文

我想在 MS Word 文档中将每个句子的第一个字母加粗。实现这一目标的好方法是什么?

I'd like to make first letter on each sentence bold in a MS Word document. What would be a good way to accomplish this?

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

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

发布评论

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

评论(3

↘紸啶 2024-09-13 18:59:02

在 VBA 中非常简单

Sub BoldFirstLetterInSentence()
Dim ad As Document
Set ad = ActiveDocument
Dim sen As Range
For Each sen In ad.Sentences
    sen.Words.First.Characters.First.Font.Bold = True
    /* sen.Words(1).Characters(1).Font.Bold = True also works */
Next
End Sub

Pretty straight-forward in VBA

Sub BoldFirstLetterInSentence()
Dim ad As Document
Set ad = ActiveDocument
Dim sen As Range
For Each sen In ad.Sentences
    sen.Words.First.Characters.First.Font.Bold = True
    /* sen.Words(1).Characters(1).Font.Bold = True also works */
Next
End Sub
澜川若宁 2024-09-13 18:59:02

这可以通过 Word 内置的高级查找+替换来完成。您需要指定一个通配符匹配表达式,例如这个表达式来选择句子分隔符和空格后面的第一个字符:

[\.\?\!] ?

您可以指定找到的每个字符在同一 UI 中的样式(它不是严格的查找/替换 - 您可以找到/风格)。请注意,上面的表达式将同时生成每个句子的第一个字符和前面的 ?/!/。大胆的。您可以通过再次搜索标点符号并取消粗体来纠正此问题。

请参阅本指南:http://www.gmayor.com/replace_using_wildcards.htm

不太程序化,我知道,但是比深入研究VBA要快得多。

This can be done with Word's built in advanced find+replace. You would need to specify a wildcard matching expression such as this one to select the first character following a sentence delimiter and space:

[\.\?\!] ?

You can specify how each character found is styled in the same UI (it is not strictly find/replace - you can find/style). Note that the expression above will make both the first character of each sentence and the preceding ?/!/. bold. You can correct this by doing another search for just the punctuation marks and un-bolding them.

See this guide: http://www.gmayor.com/replace_using_wildcards.htm

Not very programatic, I know, but much faster than delving into VBA.

記憶穿過時間隧道 2024-09-13 18:59:02

以下对我有用

Option Explicit

Public Sub SetFirstLetterBold()
    Dim i As Integer
    Dim doc As Document
    Set doc = ActiveDocument

    For i = 1 To doc.Sentences.Count
        doc.Sentences(i).Characters(1).Bold = True
    Next
End Sub

The following works for me

Option Explicit

Public Sub SetFirstLetterBold()
    Dim i As Integer
    Dim doc As Document
    Set doc = ActiveDocument

    For i = 1 To doc.Sentences.Count
        doc.Sentences(i).Characters(1).Bold = True
    Next
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文