使宏可用于任何 Visio 文档

发布于 2024-12-01 15:08:43 字数 111 浏览 0 评论 0原文

我想要创建许多宏并能够在任何 Visio 文档中使用它们。我知道使用“记录宏功能”创建宏的基本知识,但看来如此记录的宏仅适用于该 Visio 文件。我已经搜索过如何做到这一点,但尚未成功。任何帮助将不胜感激。

I want to create a number of macros and be able to use them in any Visio document. I know the rudiments of creating a macro with the "Record Macro function", but it appears that the macro so recorded is only available to that Visio file. I've searched to see how this could be done but have not had success on how to do so. Any assistance would be appreciated.

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

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

发布评论

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

评论(2

半暖夏伤 2024-12-08 15:08:43

我假设您的意思是您想要在 Visio 文档中编写代码,该代码调用另一个 Visio 文档中编写的代码。据我所知,使用 VBA 有两种方法可以实现此目的。

第一种是对 Document 对象使用 ExecuteLine 方法。您只需传入要在该文档中调用的一行 VBA 作为字符串参数,代码就会被调用。这实际上只适用于调用不带参数的宏,或者如果带参数,则仅调用字符串/数字参数。

第二种方法是保存您的文档(通常是 vss* 模板文件,如果您通过宏提供模板形状),并且在任何其他文档中您只需设置对代码文件的引用。这允许 VB 编辑器具有智能感知并查看您可以在宏文件中调用的所有方法,并且可以传递您的方法可以采用的任何类型的参数。

现在,如果您只对通过 UI 操作调用中央文件中的简单方法感兴趣,则有许多不同的方法可以执行此操作。您可以将代码分配给不同的形状,即每当该形状移动或双击时。这可以在 ShapeSheet 窗口中为“事件”部分中的形状分配。

您还可以直接在 Visio 页面上绘制命令按钮或任何其他 VBA 控件,并将宏分配给这些按钮。

或者,您可以转到“工具”->“宏”->(您的文档名称),代码文件中的每个模块都会有更多下拉菜单,您可以在其中调用任何没有参数的公共子程序。

或者,您可以构建一个工具栏(在 Visio 2010 之前的版本中)或带有调用代码的按钮的功能区界面。根据我的经验,为 VBA 解决方案构建工具栏有点糟糕。工具栏按钮必须调用您希望代码执行的文档中包含的代码。假设您已将代码全部编写并保存在 VSS 文件中,每当打开新文档时,该文件都会调用为新文档添加工具栏的方法。当您将代码分配给该工具栏上的按钮时,工具栏会假设您分配的代码位于您打开的新文档中,而不是您的 VSS 文件中。因此,要使按钮调用 VSS 文件,您的新文档中必须有一个方法,该方法使用 ExecuteLine 调用 VSS 文件中的实际代码。这很痛苦,因为现在您的用户必须使用您提供的 VST 模板文件,而不是理论上在他们想要的任何绘图上使用您的工具。

很抱歉胡言乱语,但 Visio 在如何调用代码方面非常灵活,因此您几乎可以做任何您想做的事情。

I'm assuming you mean you want to write code in a Visio document that calls code written in another Visio document. There are two ways I know of to do this with VBA.

The first is to use the ExecuteLine method on a Document object. You just pass in a line of VBA you want to call in that document as a string argument, and the code gets called. This is really only good for calling macros that take no arguments, or if they do, just string/number arguments.

The second way is to save your document (usually a vss* stencil file, if you provide template shapes with your macros), and in any other document you just set a reference to your code file. This allows the VB Editor to have intellisense and see all the methods you can call in your macro file, and makes it possible to pass whatever type of arguments that your methods can take.

Now, if you are only interested in invoking/calling simple methods in a central file through UI actions, there are many different ways to do this. You can assign code to different shapes, ie whenever that shape moves, or when it'd double clicked. This can be assigned in the ShapeSheet window for a shape in the Events section.

You can also draw command buttons or any other VBA controls right on a Visio page and assign your macros to those buttons.

Or you can go to Tools->Macros->(your document name) and there will be more dropdowns for each module in your code file, where you can call any public subs that have no arguments.

Or you can build a toolbar (in the pre-Visio 2010) or ribbon interface with buttons that call your code. Building a toolbar for a VBA solution is kinda crappy though, from my experience. A toolbar button has to call code contained in the document you want to have your code act on. So let's say you have your code all written and saved in a VSS file that, any time a new document is opened, calls a method that adds a toolbar for the new document. When you assign the code to the buttons on that toolbar, the toolbar is assuming the code you've assigned resides in the new document you've opened, not your VSS file. So, to make your buttons call your VSS file, you have to have a method in your new document that uses ExecuteLine to call your actual code in your VSS file. This is a pain, because now your user has to use a VST template file you provide, rather than, theoretically, use your tool on any drawing they want to.

Sorry for the rant, but Visio is pretty flexible in terms of how to call code, so you can probably do just about anything you want.

坏尐絯 2024-12-08 15:08:43

我的解决方案是将宏保存在模板中。只要打开模板,代码就可用于活动绘图。现在,如果我只是弄清楚如何在模板中放置“按钮”来激活特定的宏......

My solution is to save my macros in a stencil. As long as you have the stencil open, the code is available to the active drawing. Now, if I just figure out how to put "buttons" in the stencil to activate a specific macro...

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