views:

70

answers:

3

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?

+3  A: 

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.

tehblanx
+4  A: 

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
Otaku
Would you mind telling me, why this code doesn't work, when I have `option exlicit` turned on?
froeschli
It's because `sen` in the `For Each` loop is not defined and `Option Explicit` requires all variables to be defined. It is a `Range` object, so you would just need to add `Dim sen As Range` below the `Set ad...`. I've updated the code to reflect that.
Otaku
+1  A: 

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
froeschli