1

我有一个用 VBA 编写的 Excel 插件,我们称之为MyAddin.xlam.
我已将项目名称设置为MyAddin.

当我打开第二个项目并选择Tools->References...时,MyAddIn 显示得很好。一切正常。那太棒了。

但是.. 出于纯粹的审美原因,我希望列表显示My Addin在参考列表中。潜在参考列表中几乎所有可用的内容在名称中都有空格。
但是如果我尝试重命名我的项目以在名称中包含一个空格,VBA 不允许我这样做。

所以,这个问题听起来很愚蠢,有什么办法可以在“参考”列表中的 VBA 加载项的显示名称中添加空格?

我非常愿意接受“这在 VBA 中是不可能的;如果您使用另一种语言构建加载项,您只能在参考名称中添加空格”的答案,但我想知道我是否遗漏了一些简单的东西.

谢谢!

编辑,附录:本质上,我的问题是:有没有办法让“显示名称”与项目名称不同,它不关心文件命名/对象命名限制?

4

2 回答 2

2

是的,你是对的。VBA 不允许您在“属性”窗口的“项目名称”中插入空格。

如果你尝试,它会给你一个错误(见快照)

在此处输入图像描述

VB.net 也没有运气。我添加了空格并将其转换为 Excel 中的下划线。让我进行更多测试并回复您...

快照

在此处输入图像描述

跟进

呸终于!是的,在 VB.Net 中是可能的。如果您想了解更多详情,请告诉我?

在此处输入图像描述

于 2012-05-18T16:07:26.040 回答
1

You can vary the display name as it appears in the Add-ins window by editing the Title Built-in Document Property, but that doesn't help you with the name in the References window

The VBE won't let you use illegal characters in a project name of module name, but that doesn't mean it can't be done.

For example, the Analysis Toolpak - VBA add-in ATPVBAEN.XLAM has a project name of atpvbaen.xls which includes the supposedly illegal character .

Likewise, the same project has a module called VBA Functions and Subs which includes the illegal (space) character.

But the public procedures in Analysis Toolpak are still callable by using square brackets.

Sub test()

  'Run the auto_open macro in Analysis Toolpak
  [atpvbaen.xls].[VBA Functions and Subs].auto_open

End Sub

So Microsoft knows how to use illegal characters in project and module names, which is presumably done in the binary or with a special build of VBE.

EDIT

I just edited the binary of a VBA project and was able to put spaces in the VBA project name!

Interestingly, you can't export and then reimport the modules from Analysis Toolpak, as VBE still enforces the naming rules on import. Good luck getting that to work with Source Control.

EDIT: 3 FEB 2017 From the VBA file format spec: [MS-OVBA]

[module name] SHOULD be an identifier... MAY be any string of characters... MUST be less than or equal to 31 characters long.

[project name] SHOULD be an identifier... MAY be any string of characters... MUST be less than or equal to 128 characters long.

So it seems the VBE is imposing the SHOULD rule, but VBA is actually more permissive, if you are able to edit the project binary.

于 2016-10-18T03:43:19.670 回答