Results 1 to 10 of 10
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    StrConv / Replace feature (Word 2000)

    I'm having a tough time trying to convert some words in my Range to lowercase

    I've tried using the Replace function using Find, but then the macro takes forever to complete because it is constantly repaginating.

    I then went to Word VBA help and it listed this little routine:

    For Each aWord In myRange.Words
    If aWord.Text = "Franklin " Then aWord.Delete
    Next aWord

    This does not work. I can't seem to dim Word as a Word.

    I then attempted to re-write the code as follows:

    Dim n As Integer
    For n = 1 To aRange.Words.Count
    If aRange.Words(n).Text = sWord Then
    aRange.Words(n).Text = StrConv(sWord, vbLowerCase)
    End If
    Next n

    This does not work either.

    Any suggestions?

    Thank you,

    Kyle

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

    Re: StrConv / Replace feature (Word 2000)

    The words in a range are all ranges. So you should dim your variable as Range

    Find / Replace is usually much quicker than checking every word, maybe you can turn off pagination for the duration of your Macro, using
    Options.Pagination = False
    (you may need to set tye View to normal first)

    StuartR

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: StrConv / Replace feature (Word 2000)

    Did you notice the space after "Franklin " in the Help example? Look at this test snippet:

    Sub TestLCase()
    Dim wdW As Range
    For Each wdW In Selection.Words
    If wdW = "And " Then wdW.Case = wdLowerCase
    MsgBox Chr(34) & wdW & Chr(34)
    Next wdW
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: StrConv / Replace feature (Word 2000)

    Man, you're almost there... In fact, I bet this post arrives late, and you figured it out.

    <pre>Sub test()
    Dim aRange As Range
    Dim n As Integer
    Dim sWord As String
    sWord = "fox"
    Set aRange = ActiveDocument.Content
    For n = 1 To aRange.Words.Count
    If rtrim(aRange.Words(n).Text) = sWord Then
    aRange.Words(n).Text = StrConv(sWord, vbUpperCase)
    End If
    Next n

    End Sub
    </pre>

    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: StrConv / Replace feature (Word 2000)

    Related a little to this thread so continuing on (not to mention that with Search is disabled I have an excuse to be lazy). Since Word is mostly a mystery to me, I have a simple question. I have a short macro to selectively replace certain text in a long document, but I don't want to apply it to the entire document, just the selection:

    Sub Bob2Ted()
    Application.ScreenUpdating = False
    Options.Pagination = False
    ' Application.DisplayAlerts = wdAlertsNone ' tried this and it replaced through the rest of the document
    With Selection.Find
    .Text = "Bob"
    .Replacement.Text = "Ted"
    .Execute Replace:=wdReplaceAll
    End With
    ' Application.DisplayAlerts = wdAlertsAll
    Options.Pagination = True
    Application.ScreenUpdating = True
    End Sub

    My question is, how do I get rid of the "Word Finished Searching the Selection. 'n' replacements were made. Do you want to search the remainder of the document?" dialog that pops up at the end of the macro? I want to automate a "no" answer.
    -John ... I float in liquid gardens
    UTC -7ąDS

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

    Re: StrConv / Replace feature (Word 2000)

    With Selection.Find
    ...
    ...
    .Wrap = wdFindStop
    ...
    ...
    End With

    StuartR

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: StrConv / Replace feature (Word 2000)

    <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15> Gracias! Wasn't expecting the Wrap condition to solve the problem.
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: StrConv / Replace feature (Word 2000)

    Thank you Stuart. I tried to turn off the pagination as you mentioned but it would not work for me. Thanks anyway for your post.

  9. #9
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: StrConv / Replace feature (Word 2000)

    Thanks John. I did not notice the extra space. Thanks for your reply.

    Kyle

  10. #10
    Star Lounger
    Join Date
    Jan 2003
    Location
    San Francisco, California, USA
    Posts
    93
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: StrConv / Replace feature (Word 2000)

    Thanks Kevin. This worked along with the previous post regarding the extra space. Thanks for you reply.

    Kyle

Posting Permissions

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