I have a textbox in PowerPoint which I store into an array with Split. Is there any way to detect what language the text is in VBA? There will actually only be English or Chinese text, so I guess an alternative solution would be to detect if the text is not English, or is/isn't Unicode?
-
Can you provide more detail about the length and nature of the text? You could just check for the presence of vowels, but it depends on whether your English text is constituted of real English words, or just English letters. For example, if your Powerpoint textbox contained English and Chinese number plates or state codes, searching for Vowels might not be an adequate check. Likewise, if your Chinese text sometimes had English characters, then that would be a problem too.ThunderFrame– ThunderFrame2016-04-02 05:33:13 +00:00Commented Apr 2, 2016 at 5:33
-
I think this could help you: Stripping Chinese Characters with VBAJamie Garroch - MVP– Jamie Garroch - MVP2016-04-02 07:57:08 +00:00Commented Apr 2, 2016 at 7:57
-
It's song lyrics. So I'll most likely just check the first word/character of the title or verse.Koganei– Koganei2016-04-03 10:16:34 +00:00Commented Apr 3, 2016 at 10:16
2 Answers
The shape's .TextFrame.TextRange.LanguageID will tell you what language the text is set to. US English is 1033, for example. There's a list of language IDs here (use the Decimal LCID, right-hand column in this case):
https://msdn.microsoft.com/en-us/goglobal/bb964664.aspx?f=255&MSPPError=-2147217396
It's worth looking at the hex values as well. The rightmost two digits give you the main language code (Chinese is 04, for example) and the leftmost two digits identify the specific locale (PRC, Singapore, Taiwan, etc).
If you're likely to have mixed language text in a single text box, look at the LanguageID property of each .Run of text. For example, with a shape selected, try this:
Dim oRng As TextRange
Dim x As Long
With ActiveWindow.Selection.ShapeRange(1).TextFrame.TextRange
For x = 1 To .Runs.Count
Debug.Print .Runs(x).LanguageID
Next
End With