Make the first letter bold on each sentence in MS Word document

。_饼干妹妹 提交于 2019-12-10 15:38:27

问题


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?


回答1:


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



回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/3096523/make-the-first-letter-bold-on-each-sentence-in-ms-word-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!