简体   繁体   English

如何将默认大小写恢复为 VBA(Excel 2010)中的变量?

[英]How does one restore default case to a variable in VBA (Excel 2010)?

At some point I accidentally named a variable range (all lower-case) and since then the Visual Basic for Applications editor refuses to use Range (Pascal-cased);在某些时候,我不小心命名了一个变量range (全部小写),从那时起,Visual Basic for Applications 编辑器拒绝使用Range (Pascal 大小写); it will auto-correct it to lower-case.它会自动将其更正为小写。 How can I reset its "brain" to forget about my past transgression?我怎样才能重置它的“大脑”以忘记我过去的违法行为?

NOTE: I've tried doing a global replace-all, but the moment I edit any single line -- it re-corrects once again.注意:我尝试过进行全局替换,但是当我编辑任何一行时 - 它会再次重新更正。

Obviously this is a very very minor, cosmetic issue but watching the R go limp every time I type Range is irritating.显然,这是一个非常非常轻微的外观问题,但每次我输入Range时看着 R 变得跛行是令人恼火的。

You need to change the name of the variable in a declaration line ( Dim statement for example) somewhere (anywhere, actually).您需要在某处(实际上是在任何地方)的声明行(例如Dim语句)中更改变量的名称。

This is one of the most annoying "features" of the VBA IDE (as if version control weren't already hard enough with VBA, the constant case-changing drives me batty).这是 VBA IDE 最烦人的“功能”之一(好像版本控制对 VBA 来说还不够难,不断更改大小写让我发疯)。 Variables have their case changed globally in the VBA IDE, regardless of the variable's actual scope.无论变量的实际范围如何,变量的大小写在 VBA IDE 中都会全局更改。 The VBA IDE seems to take the approach of most recent declaration wins. VBA IDE 似乎采用了最近声明获胜的方法。

Usually all you need to do is just update the case in a declaration line somewhere, but VBA can be obstinate.通常您需要做的只是在某处的声明行中更新案例,但 VBA 可能很顽固。 I've yet to crack the code completely.我还没有完全破解密码。

Note: As @Scorchio points out in the comments below, the variable case is changed globally within the current project;注意:正如@Scorchio 在下面的评论中指出的那样,变量 case 在当前项目中全局更改; other projects that may be open in the VBA IDE (such as other workbooks when working in Excel) are NOT affected.可能在 VBA IDE 中打开的其他项目(例如在 Excel 中工作时的其他工作簿)不受影响。

UPDATE: I expanded on this entry in my Access/VBA blog today: VBA's Case Changing "Feature"更新:我今天在我的 Access/VBA 博客中扩展了此条目: VBA 的案例更改“功能”

Last declaration in time wins.及时的最后声明获胜。

  1. Go on first line and type Dim Range As String继续第一行并键入Dim Range As String
  2. Move to next line移动到下一行
  3. Go back and remove your Dim Range As String返回并删除您的Dim Range As String

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

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