VBA:带有韩语/法语的 Excel (.xlxs) 文件的换行符和回车符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10740995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 13:12:41  来源:igfitidea点击:

VBA: newline and carriage return character for an Excel (.xlxs) file with Korean/French

vbacharacter-encoding

提问by musicliftsme

I'm having quite a bit of trouble replacing the newline and carriage return characters in an Excel file (2010 US version and .xlxs extension).

我在替换 Excel 文件(2010 美国版和 .xlxs 扩展名)中的换行符和回车符时遇到了很多麻烦。

Previously, I have written a macro that does this successfully on a regular Excel file with English with the following code.

以前,我编写了一个宏,可以使用以下代码在英语的常规 Excel 文件上成功执行此操作。

newStr = Replace(originalStr, newline/carriage return/both, replacementStr)

Newline/carriage return/bothwould be vbNewLine (Chr(10)), vbCr (Chr(13)), or vbCrLf, respectively.

Newline/carriage return/both分别是 vbNewLine (Chr(10))、vbCr (Chr(13)) 或 vbCrLf。

I now have an Excel file with Koreans and French in it, and the newline and CR characters seem to be something else. How do I go about finding what they actually are, in terms of Chr()) or some VBA constant, and replace these characters? I need to remove all of the newlines and replace with <br />.

我现在有一个包含韩语和法语的 Excel 文件,换行符和 CR 字符似乎是别的东西。我如何找到它们的实际内容,就Chr()) 或某些 VBA 常量而言,并替换这些字符?我需要删除所有换行符并替换为<br />.

回答by Fionnuala

Can you select a relevant cell and check the characters contained, like so:

您能否选择相关单元格并检查包含的字符,如下所示:

s = Sheets("Sheet3").[e2]

For i = 1 To Len(s)
    If Asc(Mid(s, i, 1)) < 32 Then
        Debug.Print Asc(Mid(s, i, 1)); " -- "; i
    End If
Next