Excel 2013 VBA 代码中的特殊字符(字母 ?????)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27418058/
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
Special characters (letters ?????) in Excel 2013 VBA code
提问by Jelovac
I made a program in Excel 2010 VBA that contains letters like ? ? ?...
我在 Excel 2010 VBA 中制作了一个程序,其中包含诸如 ? ? ?...
Msgbox("?i?a gli?a")
works.
Msgbox("?i?a gli?a")
作品。
Looks like Excel 2013 supports those letters in cells and formulas, but not in VBA.
看起来 Excel 2013 支持单元格和公式中的这些字母,但不支持 VBA。
VBA replaces them with some symbols which aren't even on the keyboard.
VBA 用一些甚至不在键盘上的符号替换它们。
I get errors executing the code.
执行代码时出错。
I believe it's something to do with language settings.
我相信这与语言设置有关。
回答by ??c Thanh Nguy?n
As BambiLongGone stated, weird string are not likely to work. I would say your best shot is looking at this article. There 's a tool called Unicode to VBA that you can use to convert all your string in your application. For example :
正如 BambiLongGone 所说,奇怪的字符串不太可能起作用。我会说你最好的镜头是看这篇文章。有一个名为 Unicode 到 VBA 的工具,您可以使用它来转换应用程序中的所有字符串。例如 :
?i?a gli?a
will be converted to
将被转换为
ChrW$(&H10C) & "i" & ChrW$(&H10D) & "a gli" & ChrW$(&H161) & "a"
回答by BambiLongGone
VBA is ANSI. Ps in it's interactions with Windows. It's UTF16 internaly and COM is also UTF 16. But it's file format is also ANSI so typing wierd strings are not likely to work (because they can't be saved as is).
VBA 是 ANSI。Ps 与 Windows 的交互。它内部是 UTF16,COM 也是 UTF 16。但它的文件格式也是 ANSI,所以输入奇怪的字符串不太可能起作用(因为它们不能按原样保存)。
So character conversion happen automatically with a million rules controlling it (mostly undocumented in an accessible fashion).
所以字符转换会自动发生,有一百万条规则控制它(大部分没有以可访问的方式记录)。
If in trouble assign to a byte array. Maybe you bneed toread from unicode file to bypass form's ANSI.
如果遇到麻烦,分配给字节数组。也许您需要从 unicode 文件中读取以绕过表单的 ANSI。
Yourstring() = "blah blah"
你的字符串()=“等等等等”
VB treats byte arrays as strings if passed to string functions.
如果传递给字符串函数,VB 会将字节数组视为字符串。
回答by RaRdEvA
You can write manually the accents in every piece of code they appear, and you can use the "find & replace" to do it faster. If you have something like:
您可以在它们出现的每一段代码中手动编写重音符号,并且可以使用“查找和替换”来更快地完成。如果你有类似的东西:
MsgBox "Código único"
Then you can find and replace:
然后你可以找到并替换:
[ó] to [" & Chr(243) & "]
[ó] 到 [" & Chr(243) & "]
[ú] to [" & Chr(250) & "]
[ú] 到 [" & Chr(250) & "]
And so on...
等等...
And you will get:
你会得到:
MsgBox "C" & Chr(243) & "digo " & Chr(250) & "nico"
If you don't know the code for each accented letter, then you can use excel with the function "CODE" (Function Char does the opposite)
如果您不知道每个带重音字母的代码,那么您可以使用带有函数“CODE”的 excel(函数 Char 正好相反)
Also, you could use a list from the internet like this one:
此外,您可以使用互联网上的列表,如下所示:
ASCII Code - The extended ASCII table
I just had the same problem and did this procedure. Worked fine using Visual Studio Code and very fast.
我只是遇到了同样的问题并做了这个程序。使用 Visual Studio Code 运行良好,速度非常快。
回答by Miroslav Kajan
Problem is in windows regional settings: Region/Administrative/Language for non-unicode programs, which must be set to language that can handle your special characters.
问题在于 Windows 区域设置:非 unicode 程序的区域/管理/语言,必须将其设置为可以处理您的特殊字符的语言。
回答by Stjepan Morovich
Function CroatianCharacters(CroatianCharacterOrderNumber As Integer, Optional UpperCase As Boolean = True, Optional DisplayAll As Boolean = False) As String
'ISO Latin1 Extended A decimal code
Dim AllCharacters
UpperCaseLetters = "A,B,C," & ChrW(268) & "," & ChrW(262) & "," & "D," & "D" & ChrW(382) & "," & ChrW(272) & "," & _
"E,F,G,H,I,J,K,L,Lj,M,N,Nj,O,P,R,S," & ChrW(352) & ",T,U,V,Z," & ChrW(381)
LowerCaseLetters = "a,b,c," & ChrW(269) & "," & ChrW(263) & "," & "d," & "d" & ChrW(382) & "," & ChrW(273) & "," & _
"e,f,g,h,i,j,k,l,lj,m,n,nj,o,p,r,s," & ChrW(353) & ",t,u,v,z," & ChrW(382)
CroatianCharacters = LowerCaseLetters
If (UpperCase = True) Then
If (DisplayAll = False) Then
AllCharacters = Split(UpperCaseLetters, ",")
CroatianCharacters = AllCharacters(CroatianCharacterOrderNumber - 1)
Else
CroatianCharacters = UpperCaseLetters
End If
Else
If (DisplayAll = False) Then
AllCharacters = Split(LowerCaseLetters, ",")
CroatianCharacters = AllCharacters(CroatianCharacterOrderNumber - 1)
Else
CroatianCharacters = LowerCaseLetters
End If
End If
End Function