Excel VBE 导出不一致

发布于 2024-07-29 16:27:46 字数 438 浏览 2 评论 0原文

我正在从 .xls 文件导出 .bas 文件,如下所述:将 VBComponent 代码模块导出到文本文件 以将它们签入 SVN 存储库。

我遇到以下问题,该问题导致文件中变量名称的大小写发生变化,但实际上并不真实(或至少不相关)。

像这样的语句被重新格式化/重新封装:(

rngTenors.Cells(i, 1) 
changes into 
rngTenors.cells(i, 1)

微妙但仍然不同,它被我使用的 diff 工具拾取,并在生成的噪音中隐藏文件上的真正更改)

任何阻止这种情况发生的方法的想法都会受到赞赏。

I am exporting .bas files from an .xls file as outlined here: Exporting A VBComponent Code Module To A Text File to check them in into an SVN repo.

I am encountering the following issue which causes a change in casing of variable names in the files that is actually not real (or at least not relevant).

Statements like these get reformatted/recased:

rngTenors.Cells(i, 1) 
changes into 
rngTenors.cells(i, 1)

(subtle but still different and it gets picked up by the diff tool that I use and hides the real changes on the file in the noise that this generates)

Any idea of ways to prevent this from happening would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜扑 2024-08-05 16:27:46

我正在做类似的事情,但还没有看到你所经历的。 我没有使用相同的导出例程,但乍一看它们看起来很相似。

有几个问题。

1) 您是否使用显式选项,以及
你有一个名为cell的变量吗
任何地方?

2) 如果您提交,然后进行一些更改,导出 .bas 文件并再次提交,差异会是什么样子?

3) 您是否在代码感知编辑器(例如:Ultraedit)中打开并比较 .bas 文件,这可能会更改您的大小写?

我只是猜测...但是如果您将变量命名为与方法或属性相同的名称,那么 VB 编辑器的大小写可能会很奇怪。 另外,我不明白为什么您的导出会不一致地导出 .Cell 我猜测如果它导出到 .cell 那么它应该始终导出到 .cell< /code> 这不是问题。

这些只是一些想法,祝你好运:)

I'm doing something similar but haven't seen what you are experiencing. I'm not using the same export routines but they look similar at first glance.

A couple of questions.

1) Are you using option explicit, and
do you have a variable named cell
anywhere?

2) If you Commit, then make a few changes, export the .bas file and Commit again, what does the diff look like?

3) Are you opening and diffing the .bas files in a code aware editor (eg: Ultraedit) that may be changing your capitalisation?

I'm just guessing... but VB editor capitalisation can be weird if you name variables the same as methods or properties. Also i don't see why your export would inconsistently export .Cell i'm guessing if it exports to .cell then it should always export to .cell and not be a problem.

These are just some ideas, good luck :)

忆伤 2024-08-05 16:27:46

VBE 保留变量名称的内部缓存,包括大小写,因此即使您找到一个名为 cell 的变量,并将其重命名为其他名称,VBA 仍然 >认为它是一个有效的名称,因此它在该文本的所有用法中保留大小写。

您可以通过临时声明具有正确大小写的变量来欺骗 VBE 重置变量大小写(这也适用于方法上的大小写问题):

Public Cell as String

然后删除该变量。 然后,您应该发现整个项目(以及引用它的任何项目)中的所有外壳都是固定的。

The VBE keeps an internal cache of variable names, including the casing, so even though you found a variable called cell, and renamed it to be something else, VBA still thinks it is a valid name, and so it is preserving the casing across all usages of that text.

You can trick the VBE into resetting the variable casing (and this also works for casing problems on methods too) by temporarily declaring a variable with the correct casing:

Public Cell as String

And then deleting that variable. You should then find that all of the casings are fixed throughout your project (and any project that refers to it).

话少情深 2024-08-05 16:27:46

事实上,我在代码中发现了一些东西,正如上面所建议的。

dim cell

我现在已重命名该变量,此后没有发生任何重新格式化。 我期待并希望这已经解决了这个问题。 非常感谢您的帮助!

Indeed I found something in the code as was suggested above.

dim cell

I have now renamed this variable and no reformats have occurred since. I expect and hope that this has resolved the issue. Many thanks for help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文