Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find/replace LanguageId (word97-SR2)

    Here's a funny one:

    I tried to record a macro to find-and-replace text AND apply a style AND set the language to NoProofing. The NoProofing didn't seem to "stick" in the recording, even 'though the Find/Replace dialogue box indicates that it is an option (Format, Language in the Replace tab of the Edit Find dialogue box).

    So I tried tapping the period key within the "With Selection.Find"; sure 'nuff, LanguageId is available.

    Trouble is, if you de-comment the line "LanguageId", the Find/replace stops after the first replacement.

    If you leave the LanguageId commented, it replaces all occurrences of "want".

    (Unless I'm being particularly obtuse.) Word97/SR2 remember.

    <pre>Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro EDITED 12/09/02 by Christopher Greaves
    '
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("csBIU")
    With Selection.Find
    .Text = "want"
    .Replacement.Text = "WANT"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    ' .LanguageID = wdNoProofing
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    </pre>


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

    Re: Find/replace LanguageId (word97-SR2)

    Chris, you write that you want to "set the language to NoProofing". But Selection.Find.LanguageID = wdNoProofing specifies the language of the text to be found. To set the language of the replacement, you should use Selection.Find.Replacement.LanguageID = wdNoProofing.

    *** BUT ***

    Apparently, setting a style for the replacement overrides the language set by .LanguageID = ... by the language of the style. So you must either omit setting a character style and resort to explicit formatting, including language, or set the language of your style to No Proofing, and just apply the style. I would prefer the latter, but it's up to you to decide, of course.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find/replace LanguageId (word97-SR2)

    > specifies the language of the text to be found.

    Ooops! Thanks for catching that. I was so intent on seeing if a LanguageId popped up after the period that i didn't care where the period was, just so long as i saw a languageId!


    >style for the replacement overrides the language

    I agree. This is what I felt happened when first I recorded the macro.

    Interestingly enough, recording a macro that replaces text and language works(all occurrences of "the" are replaced with "THE" and NoProofing set) but the LanguageId setting is NOT recorded in the macro:

    <pre>Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 12/10/02 by Christopher Greaves
    '
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "the"
    .Replacement.Text = "THE"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    </pre>


Posting Permissions

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