Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Thanked 0 Times in 0 Posts

    Find and use capitalised words (2003/SP2)

    Hi there,

    I've had a request for a macro from a member of staff and I'm not sure whether it's possible at all, or maybe only in part. We work with very large documents and the user would like a macro to find any words within a document where the first letter is a capital, copy these words and add them to a list (anywhere - perhaps a blank page at the end of the document or even in a new blank document). A further catch is that the user would like either (a) to exclude words at the beginning of sentences or ([img]/forums/images/smilies/cool.gif[/img] if it's not possible to exclude them, then to differentiate by adding them to another list. I think I just about have a grasp of what the user is looking for, so I hope what I've written here makes sense. I'd be grateful for any thoughts/help at all.

    Thanks in anticipation,


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Find and use capitalised words (2003/SP2)

    The following macro will list all capitalised words except the first one in a sentence. The list will be created in a new document.
    Sub ListCapitalisedWords()
    Dim docSource As Document
    Dim docTarget As Document
    Dim rngSentence As Range
    Dim i As Integer
    Dim strWord As String
    Dim intAsc As Integer

    On Error GoTo ErrHandler

    Set docSource = ActiveDocument
    Set docTarget = Documents.Add
    For Each rngSentence In docSource.Sentences
    For i = 2 To rngSentence.Words.Count
    strWord = rngSentence.Words(i).Text
    intAsc = Asc(Left(strWord, 1))
    If intAsc >= 65 And intAsc <= 90 Then
    docTarget.Content.InsertAfter strWord
    End If
    Next i
    Next rngSentence

    Set rngSentence = Nothing
    Set docTarget = Nothing
    Set docSource = Nothing
    Exit Sub

    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub
    The document to be searched should be the active document when you run the macro.

    Note: the macro doesn't take capitals with accents such as

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Thanked 0 Times in 0 Posts

    Re: Find and use capitalised words (2003/SP2)

    As ever I am astounded - thanks! I don't think the user at this end has thought this through as much as they think they have, but I think they'll be more than happy with what this does for them.

    Thanks again Hans,


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts