简体   繁体   English

如何解决命名冲突的VB编辑器中代码的自动大写?

[英]How to fix the auto-capitalization of code in the VB editor with naming collision?

As noted in this old unsolved question in another site, when using variables and properties with the same names but different capitalization the Visual Basic Editor forces incorrect capitalization on the properties automatically.正如另一个站点中这个未解决的旧问题中所指出的,当使用名称相同但大小写不同的变量和属性时,Visual Basic 编辑器会自动强制属性的大小写不正确。

Dim workbook As Excel.workbook
Dim worksheet As Excel.worksheet
Dim name As String

Set workbook = Excel.Application.ThisWorkbook
Set worksheet = workbook.ActiveSheet
Set name = worksheet.name

In this example being "Excel. w orkbook", "Excel. w orksheet" and "worksheet. n ame".在此示例中为“ Excel.workbook ”、“ Excel.worksheet ”和“ worksheet.name ”。

Is there any way to fix that or turn if off in the editor?如果在编辑器中关闭,有什么方法可以解决或关闭?

The question isn't about whether it's a good idea or not to use reserved words as variable or sub/function names.问题不在于使用保留字作为变量或子/函数名称是否是一个好主意。

Wrong capitalization is the result of that You used this special word for your variable.错误的大写是因为您将这个特殊词用于变量。 And after that Editor is using that word as your variable, not the word with its functionality in VBA.之后,编辑器使用该词作为变量,而不是在 VBA 中具有其功能的词。

Editor will not know if now You want word 'workbook' as your variable and later as assigned VBA word.编辑器不知道现在您是否希望将单词“工作簿”作为变量,然后将其指定为 VBA 单词。

Try to avoid using word as variables, which are assigned to VBA language.尽量避免使用 word 作为变量,这些变量分配给 VBA 语言。

You can't overcome this.你无法克服这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM