Σάββατο 23 Φεβρουαρίου 2019

Μετατροπή ελληνικών - αγγλικών χαρακτήρων

Αλλάζετε συχνά γλώσσα πληκτρολογίου κατά τη επεξεργασία ενός κειμένου; Σας έχει τύχει να γράφετε με αγγλικό πληκτρολόγιο, κείμενο που έπρεπε να είναι στα ελληνικά, ή και αντίστροφα;

Αν απαντήσατε ναι σ' αυτές τις δύο ερωτήσεις τότε χρειάζεστε την βοήθειά μου! Και για την ακρίβεια την βοήθεια του κυρίου Αποστολίδη, που φρόντισε, χρόνια πριν, να προσθέσει την μακροεντολή που αναφέρω στη συνέχεια στα εργαλεία που συνόδευαν το Office 97 αν δεν κάνω λάθος.

Sub ChangeLang()
    '
    ' Μετατροπή χαρακτήρων Αγγλικά <--> Ελληνικά
    ' Microsoft Corporation
    ' Συντάκτης: Κυριάκος Αποστολίδης
    '

Dim SelectionSize As Integer
Dim TranslatedSelection As String
Dim CurrentCharacter As String

If Documents.Count = 0 Then Exit Sub

StatusBar = "Παρακαλώ περιμένετε..."

TranslatedSelection = ""

SelectionSize = Selection.Characters.Count
If Selection.Start = Selection.End Then
    MsgBox "Δεν έχετε επιλέξει κείμενο!"
    Exit Sub
End If
For i = 1 To SelectionSize

    CurrentCharacter = Selection.Characters(i)
    If (Selection.Characters(i).LanguageID = wdEnglishUS Or _
        Selection.Characters(i).LanguageID = wdEnglishUK) _
        And i < SelectionSize _
        And (Selection.Characters(i) = ";" Or _
            Selection.Characters(i) = ":") Then

        i = i + 1

        CurrentCharacter = CurrentCharacter & Selection.Characters(i)

      End If
      TranslatedSelection = TranslatedSelection & Translate(CurrentCharacter)
Next

Selection = TranslatedSelection
If (Selection.LanguageID = wdEnglishUS Or Selection.LanguageID = wdEnglishUK) Then
      Selection.LanguageID = wdGreek
Else
      Selection.LanguageID = wdEnglishUS
End If
End Sub

Function Translate(InputStr As String) As String
Dim OutputStr As String

Select Case (InputStr)

' SPACE remains the same (for speed added here)
    Case " ": OutputStr = " "

' Wanted Greek but used English keyboard (lower case)
    Case ";a": OutputStr = "ά"
    Case ";e": OutputStr = "έ"
    Case ";h": OutputStr = "ή"
    Case ";i": OutputStr = "ί"
    Case ";o": OutputStr = "ό"
    Case ";y": OutputStr = "ύ"
    Case ";v": OutputStr = "ώ"

    Case ":i": OutputStr = "ϊ"
    Case ":y": OutputStr = "ϋ"

    Case "q": OutputStr = ";"
    Case "w": OutputStr = "ς"
    Case "e": OutputStr = "ε"
    Case "r": OutputStr = "ρ"
    Case "t": OutputStr = "τ"
    Case "y": OutputStr = "υ"
    Case "u": OutputStr = "θ"
    Case "i": OutputStr = "ι"
    Case "o": OutputStr = "ο"
    Case "p": OutputStr = "π"
    Case "a": OutputStr = "α"
    Case "s": OutputStr = "σ"
    Case "d": OutputStr = "δ"
    Case "f": OutputStr = "φ"
    Case "g": OutputStr = "γ"
    Case "h": OutputStr = "η"
    Case "j": OutputStr = "ξ"
    Case "k": OutputStr = "κ"
    Case "l": OutputStr = "λ"
    Case "z": OutputStr = "ζ"
    Case "x": OutputStr = "χ"
    Case "c": OutputStr = "ψ"
    Case "v": OutputStr = "ω"
    Case "b": OutputStr = "β"
    Case "n": OutputStr = "ν"
    Case "m": OutputStr = "μ"

' Wanted English but used Greek keyboard (lower case)
    Case "ά": OutputStr = ";a"
    Case "έ": OutputStr = ";e"
    Case "ή": OutputStr = ";h"
    Case "ί": OutputStr = ";i"
    Case "ό": OutputStr = ";o"
    Case "ύ": OutputStr = ";y"
    Case "ώ": OutputStr = ";v"

    Case "ϊ": OutputStr = ":i"
    Case "ϋ": OutputStr = ":y"
    Case "ΐ": OutputStr = "Wi"
    Case "ΰ": OutputStr = "Wy"

    Case ";": OutputStr = "q"
    Case "ς": OutputStr = "w"
    Case "ε": OutputStr = "e"
    Case "ρ": OutputStr = "r"
    Case "τ": OutputStr = "t"
    Case "υ": OutputStr = "y"
    Case "θ": OutputStr = "u"
    Case "ι": OutputStr = "i"
    Case "ο": OutputStr = "o"
    Case "π": OutputStr = "p"
    Case "α": OutputStr = "a"
    Case "σ": OutputStr = "s"
    Case "δ": OutputStr = "d"
    Case "φ": OutputStr = "f"
    Case "γ": OutputStr = "g"
    Case "η": OutputStr = "h"
    Case "ξ": OutputStr = "j"
    Case "κ": OutputStr = "k"
    Case "λ": OutputStr = "l"
    Case "ζ": OutputStr = "z"
    Case "χ": OutputStr = "x"
    Case "ψ": OutputStr = "c"
    Case "ω": OutputStr = "v"
    Case "β": OutputStr = "b"
    Case "ν": OutputStr = "n"
    Case "μ": OutputStr = "m"

' Wanted Greek but used English keyboard (upper case)
    Case ";A": OutputStr = "Ά"
    Case ";E": OutputStr = "Έ"
    Case ";H": OutputStr = "Ή"
    Case ";I": OutputStr = "Ί"
    Case ";O": OutputStr = "Ό"
    Case ";Y": OutputStr = "Ύ"
    Case ";V": OutputStr = "Ώ"

    Case ":I": OutputStr = "Ϊ"
    Case ":Y": OutputStr = "Ϋ"

    Case "Q": OutputStr = ":"
    Case "W": OutputStr = "΅"
    Case "E": OutputStr = "Ε"
    Case "R": OutputStr = "Ρ"
    Case "T": OutputStr = "Τ"
    Case "Y": OutputStr = "Υ"
    Case "U": OutputStr = "Θ"
    Case "I": OutputStr = "Ι"
    Case "O": OutputStr = "Ο"
    Case "P": OutputStr = "Π"
    Case "A": OutputStr = "Α"
    Case "S": OutputStr = "Σ"
    Case "D": OutputStr = "Δ"
    Case "F": OutputStr = "Φ"
    Case "G": OutputStr = "Γ"
    Case "H": OutputStr = "Η"
    Case "J": OutputStr = "Ξ"
    Case "K": OutputStr = "Κ"
    Case "L": OutputStr = "Λ"
    Case "Z": OutputStr = "Ζ"
    Case "X": OutputStr = "Χ"
    Case "C": OutputStr = "Ψ"
    Case "V": OutputStr = "Ω"
    Case "B": OutputStr = "Β"
    Case "N": OutputStr = "Ν"
    Case "M": OutputStr = "Μ"

' Wanted English but used Greek keyboard (upper case)
    Case ":": OutputStr = "Q"
    Case "΅": OutputStr = "W"
    Case "Ε": OutputStr = "E"
    Case "Ρ": OutputStr = "R"
    Case "Τ": OutputStr = "T"
    Case "Υ": OutputStr = "Y"
    Case "Θ": OutputStr = "U"
    Case "Ι": OutputStr = "I"
    Case "Ο": OutputStr = "O"
    Case "Π": OutputStr = "P"
    Case "Α": OutputStr = "A"
    Case "Σ": OutputStr = "S"
    Case "Δ": OutputStr = "D"
    Case "Φ": OutputStr = "F"
    Case "Γ": OutputStr = "G"
    Case "Η": OutputStr = "H"
    Case "Ξ": OutputStr = "J"
    Case "Κ": OutputStr = "K"
    Case "Λ": OutputStr = "L"
    Case "Ζ": OutputStr = "Z"
    Case "Χ": OutputStr = "X"
    Case "Ψ": OutputStr = "C"
    Case "Ω": OutputStr = "V"
    Case "Β": OutputStr = "B"
    Case "Ν": OutputStr = "N"
    Case "Μ": OutputStr = "M"

    Case Else: OutputStr = InputStr

End Select

Translate = OutputStr

End Function

Αν δεν ξέρετε τι να κάνετε με τον κώδικα δείτε το θέμα Πώς θα χρησιμοποιήσω τον κώδικα μιας μακροεντολής.

Σύνοψη
Θέμα
Μετατροπή ελληνικών - αγγλικών χαρακτήρων
Κείμενο
Γιώργος ο Αδαής
Συμβολή

– Ενσωματωμένα αρχεία Βοήθειας του Word

Ταυτότητα
2.02.004/0011
Έκδοση
10/3/10
Αναθεώρηση
23/2/19

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου