0

I am trying to set the text in a Powerpoint text box to Chinese characters from a .txt file encoded in UTF-8, using VBA. Currently, I have

Set TradBox = Current.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 500, 250)
Set SimpBox = Current.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 250, 500, 250)
TradBox.TextFrame.TextRange.Text = DataLineTrad
SimpBox.TextFrame.TextRange.Text = DataLineSimp

Where DataLineTrad and Simp are strings of Chinese characters. This results in gibberish, like 禮讓. How can I change the text box so its encoding matches the text I am trying to enter?

Lawrence Pang
  • 207
  • 1
  • 3
  • 5
  • This may help [Save text file UTF-8 encoded with VBA](https://stackoverflow.com/questions/2524703/save-text-file-utf-8-encoded-with-vba) – PatricK Jun 08 '17 at 03:33
  • What are the values of DataLineTrad and DataLineSimp? As a test, I added two text boxes to a slide, added English text to one, Japanese text to another (I don't have Chinese installed, but the issues should be similar). Then in code I set the text of the English text box to be = the text of the Japanese text box and it worked. So I wonder if there's something amiss with your variable contents. – Steve Rindsberg Jun 08 '17 at 17:27

1 Answers1

0

The solution is to tweak the OS to use the desired language for non-unicode programs in Windows.

Follow instructions (minus the Registry hack) in How To Display Foreign Characters In Excel VBE.

I just tested on my English Windows 7 Ent x64 with Office 2010 x86, and worked like charm!

PatricK
  • 6,375
  • 1
  • 21
  • 25