+ Reply to Thread
Results 1 to 16 of 16

Conditional replace accented characters with non-accented ones

  1. #1
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Conditional replace accented characters with non-accented ones

    I want to be able to correct a specific type of mistake in Greek (free) text. For any word that starts with an accented vowel or εύ, if there is anywhere in that word another instance of an accented vowel, then replace the first instance with the non-accented counterpart of that vowel. It should respect capitalization and replace with the capital counterpart in case it is capital.

    (In the attached file, 3 sheets, 1 with vowel list, 2 with example replacements, 3 with free Greek text with words for correction).

    For example

    Find Replace
    άγώνας αγώνας
    άδελφός αδελφός
    άερόστατο αερόστατο
    άθέτησις αθέτησις
    εύρέσεως ευρέσεως
    εύρύτης ευρύτης
    εύχέλαιο ευχέλαιο

    Accented Non-Accented
    ά α
    έ ε
    ή η
    ΐ ι
    ϊ ι
    ί ι
    ό ο
    ύ υ
    ΰ υ
    ώ ω
    εύ ευ
    Attached Files Attached Files
    Last edited by greek; 04-23-2014 at 05:17 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Conditional replace accented characters with non-accented ones

    You've posted this in the Word Programming area of the forum.

    Are you sure that's where it should be. The attachment is I believe an Excel file. Would you like me to move the post to an Excel area of the forum?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Re: Conditional replace accented characters with non-accented ones

    Hi Richard,

    I want to run the macro in Word, I used Excel file as reference as it seemed better suited to structure the info.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Conditional replace accented characters with non-accented ones

    I've answered a similar question before. See: http://www.excelforum.com/word-progr...ml#post3624829
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Re: Conditional replace accented characters with non-accented ones

    Hi Paul,

    This is a very different scenario in the sense that the point is not replacing a character with another one, but replacing a character on condition that another x character appears in the same word.

    Thank you for your help in the other topic

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Conditional replace accented characters with non-accented ones

    I appreciate the differences, but the value ranges for the characters you'll be working with are the same and the code in that thread shows how you can go about specifying those characters and their replacements. One potential issue I can foresee is the need to handle hard & soft breathings on first or second characters that may or may not be accented in addition to those breathings. So perhaps you could clarify whether your text has hard & soft breathings.
    Last edited by macropod; 04-19-2014 at 01:41 AM.

  7. #7
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Re: Conditional replace accented characters with non-accented ones

    Paul, the range of characters is almost entirely different; in the thread you refer to it is Greek extended (and I only posted a small subset of them there just for example's sake), in this case, it is Greek (Modern) and I have posted all the accented characters. The remaining, possible characters in-between the accented ones are Modern Greek, i.e. [α-ω] range.

    http://en.wikibooks.org/wiki/Modern_Greek/Alphabet
    Last edited by greek; 04-19-2014 at 03:52 PM.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Conditional replace accented characters with non-accented ones

    Try:
    Please Login or Register  to view this content.
    Last edited by macropod; 04-20-2014 at 08:28 AM.

  9. #9
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Re: Conditional replace accented characters with non-accented ones

    Wow, thanks, Paul!

    Seems to work on all words except for ones starting with capital, i.e. Έλευσίνια should be made Ελευσίνια. Also, when I run it an exclamation message box appears with no other text and then the macro runs when I click OK.

    Meanwhile I had gone as far as:
    Find: <ά(*)([όέήύίΰϊώ]*>)
    Replace: α\1\2

    Could not figure out how to make the first character change so that it works for all characters needing replacement, i.e. define in the Replace operation the non accented character version of the character found, when there is a range of characters involved.
    Last edited by greek; 04-20-2014 at 04:26 AM.

  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Conditional replace accented characters with non-accented ones

    Regarding your Find/Replace approach, the problem is there is no way of defining the variable replacement. And, although one could specify the Find string as:
    <[ΆΌΈΉΎΊΫΪΏάόέήύίΰϊώ]*[άόέήύίΰϊώ]*>
    you can't simply encode the characters that way in VBA - you need to use the character codes as I have done - and you would still have the complication of using a loop to determine the replacement character. That approach might be slightly more efficient than the one I've taken and I might come back to that later.

    In the meantime, the message box was just left over from testing and expanding the macro to handle capitals is easy enough:
    Please Login or Register  to view this content.
    Last edited by macropod; 04-20-2014 at 09:03 AM.

  11. #11
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Re: Conditional replace accented characters with non-accented ones

    Thanks, Paul!
    In the same vein I thought of trying something like this
    (<[άόέήίύώ])(*[άόέήίύώϊϋΰΐ]*>)
    b\1c\2

    Then use the added characters (b and c) to change first accented character to bold and then do a Find for all bold characters, mass change them to uppercase, mass change them to lowercase, and accent is gone.

    My only problem is that the expression would span more than one word (for example it would find this "ότι η ομάδα"), i.e. I do not know how not to make it "greedy" or how to exclude space from the possible matches, trying [! ] did not seem to do the trick,
    Last edited by greek; 04-20-2014 at 11:25 AM.

  12. #12
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Conditional replace accented characters with non-accented ones

    Try the following update - it should be much faster than the pervious versions. The reasons for that are twofold:
    1. The Find expressions only find words that both begin with an accented character (or character pair in the case of εύ) and contain at least one more accented character, instead of just every word that starts with an accented character; and
    2. The Execute expression uses ReplaceAll instead of having to process each found word individually.
    The reason for there being four Find expressions character/pair is to cater for words that may (a) have an accented 2nd character; (b) have an accented 3rd or later character; and (c) words beginning with both lower & upper case. I haven't bothered with words that are entirely upper case, but I expect you can see from the code how that might be handled.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Re: Conditional replace accented characters with non-accented ones

    Yes, that works very well too, Paul, apart from missing "Εύτυχής" which was not missed by previous version. I wonder though why, in some Find/Replace code, when one has track changes on, you get entirely different results!

  14. #14
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Conditional replace accented characters with non-accented ones

    [QUOTE=greek;3668901]Yes, that works very well too, Paul, apart from missing "Εύτυχής" which was not missed by previous version.[QUOTE]
    Oops! I capitalised the wrong character. Replace:
    Please Login or Register  to view this content.
    with:
    Please Login or Register  to view this content.
    I wonder though why, in some Find/Replace code, when one has track changes on, you get entirely different results!
    Track Changes has some unpredictable effects. Sometimes, for example, you need to change '.Forward = True' to '.Forward = False' to get the right result!

  15. #15
    Forum Contributor
    Join Date
    06-09-2009
    Location
    Greece
    MS-Off Ver
    Office 365
    Posts
    133

    Re: Conditional replace accented characters with non-accented ones

    Amazing, yes much faster! I wish I could do something more to thank you for your help!

    For some strange reason it misses Εύγούλα (but not εύγούλα).

    By the way, I tried to add some extra vowel pairs (same functionality as for εύ -> ευ or Εύ -> Ευ)

    αύ αυ
    ού ου
    εί ει
    οί οι
    αί αι

    But when I tried something like this for αύ it did nothing.:

    Please Login or Register  to view this content.
    Last edited by greek; 04-22-2014 at 01:06 PM.

  16. #16
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Conditional replace accented characters with non-accented ones

    Try:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Replace/remove accented characters
    By guest2013 in forum Excel General
    Replies: 3
    Last Post: 08-19-2013, 01:46 AM
  2. [SOLVED] find and replace to not replace characters found as wildcards
    By sabutler4 in forum Excel General
    Replies: 4
    Last Post: 07-03-2013, 06:48 PM
  3. Macro to replace European characters with non "special" English characters?
    By johanna0507 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2012, 09:13 AM
  4. Sort on accented (French) characters
    By greek in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-30-2011, 06:43 AM
  5. How do I replace just a few characters?
    By Tomsriv in forum Excel General
    Replies: 3
    Last Post: 08-14-2006, 07:09 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1