VBA for Word; Capitalization of part of a sentence

Posted on 2012-08-18
Last Modified: 2012-09-02
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
Question by:jbotts
    LVL 76

    Accepted Solution

    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

    Author Closing Comment

    Thanks for the information. This with some self education about ranges in Word solved the problem. Thanks.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
    Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now