MS Access VBA 代码编辑器字符编码和复制/粘贴

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22560121/
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-12 02:26:18  来源:igfitidea点击:

MS Access VBA code editor character encoding and copy/paste

vbams-accessaccess-vba

提问by parakmiakos

What is the actual encoding used in Access' VBA editor? I have been searching for a concrete answer for quite a while but with no luck.

Access 的 VBA 编辑器中使用的实际编码是什么?我一直在寻找一个具体的答案很长一段时间,但没有运气。

I thought it was UTF-8 but I'm not very certain.

我以为是 UTF-8,但我不太确定。

My main issue is that when writing a query in VBA I sometimes need to test it in Access' query editor. When copy-pasting however, I lose my native characters (greek in my case) as they turn to gibberish.

我的主要问题是,在 VBA 中编写查询时,有时需要在 Access 的查询编辑器中对其进行测试。然而,当复制粘贴时,我失去了我的母语字符(在我的例子中是希腊语),因为它们变成了胡言乱语。

I have tried pasting in a text editor and saving it as different encodings but I can never recover the original characters.

我尝试在文本编辑器中粘贴并将其另存为不同的编码,但我永远无法恢复原始字符。

Thanks in advance.

提前致谢。

Edit

编辑

Let me explain this a bit further:

让我进一步解释一下:

As you can see I can write my greek characters in the VBA editor normally:

如您所见,我可以正常在 VBA 编辑器中编写希腊字符:

sample in vba editor

vba 编辑器中的示例

However, copying the first line in Access' query editor, I get the following:

但是,在 Access 的查询编辑器中复制第一行,我得到以下信息:

paste in query editor

粘贴到查询编辑器中

Same goes for a simple text editor:

简单的文本编辑器也是如此:

text editor

文本编辑器

So I am inclined to think that the problem lies inside the clipboard, due to the encoding used for the greek characters. I guess they are not Unicode, as I indeed have to make the change in the System Locale for non-unicode characters. So how are these characters saved/copied? In what encoding?

所以我倾向于认为问题出在剪贴板内部,因为希腊字符使用了编码。我想它们不是 Unicode,因为我确实必须对非 Unicode 字符的系统区域设置进行更改。那么这些字符是如何保存/复制的呢?用什么编码?

Answer

回答

Actually this problem was solved by switching the keyboard input language to greek (EL), when copying the actual test string.

实际上这个问题是通过在复制实际测试字符串时将键盘输入语言切换为希腊语 (EL) 来解决的。

I am still not sure however, as to why that happens. If anyone can provide some insight into this, I would love to hear it.

然而,我仍然不确定为什么会发生这种情况。如果有人可以对此提供一些见解,我很乐意听到。

Thanks again

再次感谢

回答by Gord Thompson

The VBA editor does not support Unicode characters, either for input or display. Instead, it uses the older Windows technology called "code pages" to provide support for non-ASCII characters.

VBA 编辑器不支持用于输入或显示的 Unicode 字符。相反,它使用称为“代码页”的较旧的 Windows 技术来提供对非 ASCII 字符的支持。

So, the character encoding in the VBA editor corresponds to the code page that is used by the Windows system locale as specified in the "Regional and Language Options" control panel. For example, with my system locale set to "Greek (Greece)"

因此,VBA 编辑器中的字符编码对应于“区域和语言选项”控制面板中指定的 Windows 系统区域设置使用的代码页。例如,我的系统区域设置为“Greek (Greece)”

cpGreek.png

cpGreek.png

I can enter Greek characters into my VBA code

我可以在我的 VBA 代码中输入希腊字符

vbaGreek.png

vbaGreek.png

However, if I switch my Windows system locale back to "English (United States)"

但是,如果我将 Windows 系统区域设置切换回“英语(美国)”

cpUS.png

cpUS.png

and re-open my VBA project, the Greek characters have changed to the corresponding characters in the new code page

并重新打开我的 VBA 项目,希腊字符已更改为新代码页中的相应字符

vbaUS.png

vbaUS.png

回答by ndemou

If "Control Panel" -> "Regional and Language Options" -> "System Locale" is set correctly but you still suffer from this problem some times then note that while you're copy-pastingyour keyboard layout must be switched to the non-English language.

如果“控制面板”->“区域和语言选项”->“系统区域设置”设置正确,但有时您仍然遇到此问题,请注意,在复制粘贴时,您的键盘布局必须切换到非-英语。

This is applicable to all non-unicode-aware applications not only VBA.

这不仅适用于 VBA,而且适用于所有非 Unicode 感知应用程序。

Creditgoes to @parakmiakos

信用去@parakmiakos

回答by user3745444

I had a similar problem with Cyrillic characters. Part of the problem is solved when set the System locale correctly.

我对西里尔字符有类似的问题。当正确设置系统区域设置时,部分问题得到解决。

However, The VBA editor still does not recognize cyrillic characters when it has to interpret them from inside itself.

然而,当 VBA 编辑器必须从内部解释西里尔字符时,它仍然无法识别西里尔字符。

For example it can not display characters from the command:

例如它不能显示命令中的字符:

Msgbox "Здравей"

but if the sheet name is in cyrillic characters it does it well:

但如果工作表名称是西里尔字符,它会做得很好:

Msgbox Activesheet.Name

Finally, it turned out that these kind of problems were solved when I changed to 32 bits version of MS Office.

最后,当我换到32位版本的MS Office时,这些问题都得到了解决。

回答by Alan Waage

details in this: http://www.pcreview.co.uk/forums/use-greek-characters-visual-basic-editor-t2097705.html

详细信息:http: //www.pcreview.co.uk/forums/use-greek-characters-visual-basic-editor-t2097705.html

Looks like making sure your OS is set properly, and font choice inside the VBA editor.

看起来确保您的操作系统设置正确,并在 VBA 编辑器中选择字体。