Consulting

Results 1 to 9 of 9

Thread: VBA, Style names, Find-Replace Special Character Codes, and non-English versions of W

  1. #1

    VBA, Style names, Find-Replace Special Character Codes, and non-English versions of W

    This post started off as a query, but I have since resolved most of the issues ... however ...

    I have a collection of macros that are being used by a friend in the Netherlands who is using the Dutch version of Word on English language documents that are set to UK English. One of these routines sets text to the 'Normal' style (but retains all font attributes). The 'Normal' style is called 'Standaard' in the Dutch version. Word was saying that it didn't recognize the style 'Normal' even though most of the document is in this style - when you look at it in an English version of Word. I think I've fixed this by using wdStyleNormal in place of "Normal". Likewise for any other built-in style names.

    There is another issue using the special characters in Find-Replace dialogues. For example, ^t for Tab is not recognized by the Dutch Word, and likewise other Dutch special characters. I have got around this by using the relevant decimal number. eg. ^9 or vbTab for tab, ^255 for non-breaking space, etc. But does anyone know how to handle ^f and ^e for endnotes and footnotes in VBA for all language versions of Word?

    Need to change the title of this thread to "VBA, Style names, Find-Replace Special Character Codes, and non-English versions of Word"
    Last edited by Paul_Hossler; 04-04-2018 at 10:45 AM. Reason: Mostly resolved the issue

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    https://support.office.com/en-us/art...rs=en-US&ad=US


    NBS is ^160
    Footnote is ^2
    Endnotes seem to be only ^e
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Thanks. Oddly, ^160 does not find hard spaces in my version of Word (EnglishUK, 2003), but ^255 does. I don't know what works with English versions of Word 2007, 2010, 2013, 2016, 365. But ^255 does not work with my friend's Dutch version (prob. 2010 or 2013), so I'll try ^160. I'm using the function below, and for English versions will stick with ^s, which seems to be universal to all English versions. I'll deal with other language versions if they crop up.

    Function hs () As String
        If Application.LanguageSettings.LanguagePreferredForEditing(msoLanguageIDDutch) = True Then
            hS = "^160"             ' or whatever special character sequence is used in Dutch
        Else
            hS = "^s"
        End If
    End Function

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Depending on the context, use ^0160 or Chr(160) for a standard non-breaking space. There are other non-breaking space characters, too (e.g. Unicode 202F gives a Narrow No-Break Space).
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Thanks. That does the trick!

  6. #6
    Now here's strange thing. This bit of code works in Word 2003/2010/2013/2016 Office apps (English versions), but does not work in my friend's Dutch version, where the wildcard search string is rejected as an invalid search string. Likewise, using ([ ^s]){2,}

    ^s is the valid special character sequence for non-breaking space.

    .Text = "([ ^0160]){2,}": .Replacement.Text = " ": .Forward = True: .Wrap = wdFindStop
            .MatchWildcards = True: .Execute replace:=wdReplaceAll
    However, this bit of code works on both systems:

    .Text = "^w": .Replacement.Text = " ": .Forward = True: .Wrap = wdFindStop
            .MatchWildcards = False: .Execute replace:=wdReplaceAll
    Can anyone see why ([ ^0160]){2,} and ([ ^s]){2,} are treated as invalid strings in a Dutch version of Word 2010, but not in English versions?

  7. #7
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    In systems using non-Engish regional settings, one typically needs to replace the comma separator in the wildcard Find expression with a semi-colon. For example:
    Find = [ ^0160]{2,}
    becomes:
    Find = [ ^0160]{2;}
    PS: You don't need the parentheses.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  8. #8
    Umm.... Thanks. Very interesting. Also, I think maybe it should be ([ ^0160]{2,}) not ([ ^0160]){2,}, although my version of Word accepts both. My English version of Word does not accept the ; in place of a , But yes, the parentheses are not required for this operation.

    Hope this dialogue helps someone, somewhere, sometime ... It's certainly helped me!

    Thanks for the help from the two Pauls. I'll mark the thread as solved.


  9. #9
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by johndavidson View Post
    I think maybe it should be ([ ^0160]{2,}) not ([ ^0160]){2,}, although my version of Word accepts both.
    Where the closing parenthesis should be (when needed) depends on what you're using them for.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

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