如何将VBA中的非ASCII字符写入Excel工作表?

我在VBA中读取一个相当大的文本文件。 源文件包含来自国际会议的各种文本数据,并且我将这些数据的提取部分以有组织的格式重写为Excel表单。 我已经把例程的重要部分放在下面。 (我是一个原始的程序员,所以我使用原始的方法,抱歉我的不好的forms。

问题来自不是简单的ASCII字符的字符的位置。 文本文件包含各种条目,如“慕尼黑”。 当写入Excel文件时,文本被严重损坏。 在这种情况下,我得到“München”。 真烦人的是,我可以从文本文件复制文本,并将其粘贴到Excel中,没有问题。 但是手工logging太多了。 我真的希望原始(非ASCII)字符写在电子表格上!

我花了相当长的时间寻找一个解决scheme,我发现了两个相关的线程。 首先,在这里的第一个答案中描述了一个名为“binaryStream”的东西: Excel VBA – 导出为UTF-8它与我所要做的并不是非常接近,我无法弄清楚我需要的部分。

还有用VBA编码的保存文本文件UTF-8,它描述了如何将UTF-8数据写入文本文件。 差不多,但我想写一个Excel电子表格!

有什么build议吗?

Sub ParseText() Dim myFile As String, Author1 As String, Author2 As String Dim dept As String, inst As String, country As String Dim title As String, LineText As String Dim nSourceFile As Integer, NewRecord As Boolean Dim First13 As String, nn As Integer, Row As Integer, LineText2 As String myFile = Application.GetOpenFilename() nSourceFile = FreeFile Open myFile For Input As #nSourceFile Row = 2 While Not EOF(nSourceFile) Line Input #nSourceFile, LineText ''This is a blank line Line Input #nSourceFile, LineText ''This has both first and last name Author1 = Right(LineText, Len(LineText) - 2) Author2 = RTrim(Left(Author1, Len(Author1) - 1)) LineText = Author2 nn = InStrRev(LineText, " ") Author1 = RTrim(Left(LineText, nn)) Author2 = RTrim(Right(LineText, Len(LineText) - nn)) nn = Len(Author2) LineText = LCase(Right(Author2, nn - 1)) Author2 = Left(Author2, 1) & LineText Cells(Row, 1) = Author1 Cells(Row, 2) = Author2 Row = Row + 1 Wend '' reached the end of file End Sub 

答案在评论和OP接受:

“你也可以将源文件转换为UTF-16LE(即Windows内部的Unicode,记事本可以将其转换),然后在读取VBA代码的内部时,将string转换为StrConv和vbFromUnicode标志” – z̫͋