Results 1 to 13 of 13
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Capitalization procedure (2003)

    My team is working on collection of some fairly long documents. We have decided that we will always capitalize a small number of specific words: Soldier, Army, and Recruiter. Not all our authors have learned how to set up Word to automatically capitalize those words. Of course, the editors can run Find & Replace to fix those errors, but it occurred to me today that it might be possible to build a macro to handle that chore quickly and efficiently. Can someone suggest how to construct such a macro?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Capitalization procedure (2003)

    Would the macro set up AutoCorrect entries to cover future typing, and also do a Find and Replace to catch any that were missed? I guess I'm not clear on what else would be appropriate...

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capitalization procedure (2003)

    Does this do what you want?

    Sub Capitalize()
    Dim arrWords
    Dim i As Integer
    arrWords = Array("army", "recruiter", "soldier")
    For i = LBound(arrWords) To UBound(arrWords)
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Execute FindText:=arrWords(i), MatchWholeWord:=True, _
    ReplaceWith:=UCase(arrWords(i)), Replace:=wdReplaceAll
    End With
    Next i
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Capitalization procedure (2003)

    Instead of the line which reads
    <code>ReplaceWith:=UCase(arrWords(i)), Replace:=wdReplaceAll</code>
    you might want
    <code>ReplaceWith:=strconv(arrWords(i),vbProperCas e), Replace:=wdReplaceAll</code>

    This will give the requested result of Army, Soldier etc, instead of ARMY, SOLDIER etc.

    StuartR

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capitalization procedure (2003)

    I read the question differently, but you're probably correct.

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Capitalization procedure (2003)

    Hans, Stuart, et al: You're my heroes! That's exactly what I'm looking for! Thank you very much! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

    By the way, Stuart: You are correct

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Capitalization procedure (2003)

    Good morning, Hans et al:

    The macro you folks gave me works great on my computer, and I was eager to share it with a colleague who really needs it. I copied and pasted the macro from the VBE into an email message. This morning I was in her office and talked her through copying the macro text from the message and pasting it into a new Word macro. To my dismay, the text instantly displayed two lines in red...a compile error. Here's how it looked:

    <font face="Georgia"> Dim arrWords
    Dim i As Integer

    arrWords = Array("army", "recruiter", "recruiters", "soldier", "soldiers")
    For i = LBound(arrWords) To UBound(arrWords)
    With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting

    <font color=red>.Execute FindText:=arrWords(i), MatchWholeWord:=True, _
    ReplaceWith:=StrConv(arrWords(i), vbProperCase), Replace:=wdReplaceAll</font color=red>

    End With
    Next i
    End Sub</font face=georgia>

    I've examined the text carefully, and I don't see any discrepancy. I'm just a novice with this VBA stuff, so I'm wondering what I could have overlooked...? Maybe my colleague's computer is missing some references or something? <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capitalization procedure (2003)

    Check Tools | References... in the Visual Basic Editor for this user. Any MISSING references?

    It might be a good idea to delete the macro and copy/paste it anew.

    BTW, which version of Word is your colleague using?

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Capitalization procedure (2003)

    She's using Office XP. I'm not sure of her knowledge level re: the VBE. I'll probably have to go to her desk to check the references thing.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capitalization procedure (2003)

    The code should work in Word 2002 (XP) - that's what I am using. It only needs references for Visual Basic for Application and Microsoft Word 10.0 Object Library, but those are standard and can't be turned off.
    It's probably best to check things personally.

  11. #11
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    1,560
    Thanks
    37
    Thanked 1 Time in 1 Post

    Re: Capitalization procedure (2003)

    OK, so there does not appear to be anything wrong with the code. Just now I looked at my references (I'm using Office 2003 or 11), and I see the following checked:

    Visual Basic for Applications
    Microsoft Word 11.0 Object Library
    OLE Automation
    Microsoft Office 11.0 Object Library


    When I look at my colleague's system, I can expect to see all the above (except it'll say 10.0). Assuming all the above are in order, what else could be at fault? Or

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capitalization procedure (2003)

    Those four (with 10.0 instead of 11.0) are the expected ones for Word 2002. The first two are required and cannot be removed, the latter two are set by default but are not required. If there is a MISSING reference, clear its check box and click OK.

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Capitalization procedure (2003)

    You might try exporting the module containing the macro to a .bas file, renaming it to an e-mail-safe .txt extension and forwarding it that way. Just in case the e-mailing process is causing the problem.

Posting Permissions

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