Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 812
  • Last Modified:

VBA for Word; Capitalization of part of a sentence

In Access 2007 I am writing to a Word document using Ranges instead of Selections. I want to capitlaize the first 5 words of a phrase ending with a colon. I use the following code which works, but was wondering if this can be done without using a For loop.
 
        .InsertAfter vbCr & "Status on Admission to CareConnect: "
        .InsertAfter rs("CC_OriginalStatus").Value
        .Paragraphs.Last.Range.Font.Bold = False
        Dim i As Integer
        For i = 1 To 5 Step 1
            .Paragraphs.Last.Range.Words(i).Font.Bold = True
        Next
0
jbotts
Asked:
jbotts
1 Solution
 
GrahamSkanRetiredCommented:
You can doi somethig like this:

Function Capitalise(BigRange As Range) As String
    Dim rng As Range
   
    Set rng = BigRange
    rng.End = BigRange.Words(5).End
    Debug.Print rng.Text
    rng.Case = wdUpperCase
    Debug.Print rng.Text
   
End Function
0
 
jbottsAuthor Commented:
Thanks for the information. This with some self education about ranges in Word solved the problem. Thanks.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now