如何将默认情况恢复到 VBA (Excel 2010) 中的变量?

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

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

excelvbaeditorexcel-2010

提问by Neil C. Obremski

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); it will auto-correct it to lower-case. How can I reset its "brain" to forget about my past transgression?

在某些时候,我不小心命名了一个变量range(全部小写),此后 Visual Basic for Applications 编辑器拒绝使用Range(Pascal-cased);它会自动将其更正为小写。我怎样才能重置它的“大脑”以忘记我过去的过犯?

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 veryminor, cosmetic issue but watching the R go limp every time I type Rangeis irritating.

显然,这是一个非常非常小的外观问题,但每次我打字时看着 R 变得跛行Range是令人恼火的。

回答by mwolfe02

You need to change the name of the variable in a declaration line (Dimstatement 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). Variables have their case changed globally in the VBA IDE, regardless of the variable's actual scope.The VBA IDE seems to take the approach of most recent declaration wins.

这是 VBA IDE 最令人讨厌的“功能”之一(好像 VBA 的版本控制还不够难,不断变化的大小写让我很生气)。 变量的大小写在 VBA IDE 中全局更改,而不管变量的实际范围如何。VBA IDE 似乎采用了最近宣布获胜的方法。

Usuallyall you need to do is just update the case in a declaration line somewhere, but VBA can be obstinate. I've yet to crack the code completely.

通常您需要做的只是在某处的声明行中更新案例,但 VBA 可能很顽固。我还没有完全破解密码。

Note: As @Scorchio points out in the comments below, the variable case is changed globally within the current project; other projects that may be open in the VBA IDE (such as other workbooks when working in Excel) are NOT affected.

注意:正如@Scorchio 在下面的评论中指出的,变量 case 在当前项目中是全局更改的;可能在 VBA IDE 中打开的其他项目(例如在 Excel 中工作时的其他工作簿)不受影响。

回答by thanos.a

Last declaration in time wins.

最后一次宣布获胜。

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