How can I call a VBA macro that is defined in a different file?

霸气de小男生 提交于 2019-12-24 19:23:50

问题


The situation is the following:

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

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

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

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


回答1:


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"

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...

Hope that helps




回答2:


Never worked with visio before, but a quick browse got me these for excel vba; I'm not sure if it'll work for you, but try it out:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=279
http://www.xtremevbtalk.com/showthread.php?t=139135



来源:https://stackoverflow.com/questions/1669377/how-can-i-call-a-vba-macro-that-is-defined-in-a-different-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!