如何调用在不同文件中定义的 VBA 宏? [英] How can I call a VBA macro that is defined in a different file?

查看:56
本文介绍了如何调用在不同文件中定义的 VBA 宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况如下:

宏 Foo 在文件 foo.vss 中定义宏条在文件 bar.vsd 中定义.

Macro Foo is defined in File foo.vss Macro Bar is defined in File bar.vsd.

Bar() 在某个时候应该调用 Foo().这可能吗?

Bar() is at some point supposed to call Foo(). Is that possible?

如果有帮助:
foo.vss 是在 bar.vsd 中打开的模板文件.

If it helps:
foo.vss is a stencil file that is opened in bar.vsd.

仅供参考:
他们强迫我使用 Visio/vba.它是一个奇怪的旧系统,从图表中生成 SQL,真的很丑.

FYI:
They are forcing me to use Visio/vba. Its a strange old System that generates SQL from the diagrams, really ugly.

推荐答案

这是可能的,对包含代码的文档使用 ExecuteLine 方法.

This is possible, using the ExecuteLine method on the document containing the code.

所以在你的例子中,它会是这样的:

So in your example it would be something like:

Visio.Documents("Foo.vss").ExecuteLine "Foo"

Visio.Documents("Foo.vss").ExecuteLine "Foo"

我经常使用它来从 Excel 调用 Visio 宏,并且效果很好.ExecuteLine 似乎会执行您可以从立即窗口执行的几乎所有内容,因此您实际上是传入了一行有效的 VBA 代码...

I've used this quite a bit for calling Visio macros from Excel and it's worked quite nicely. ExecuteLine seems like it will execute pretty much anything you can execute from the Immediate Window, so you actually are passing in a line of valid VBA code...

希望有帮助

这篇关于如何调用在不同文件中定义的 VBA 宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆