如何在 Visio vba 中引用形状
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2262296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to refer to shapes in Visio vba
提问by dbjohn
How does one create specific shapes in microsoft visio that are selectable through the normal interface? I am looking for code like ActivePage.addShape(type: person, 100,100, 50,50)
如何在 microsoft visio 中创建可通过普通界面选择的特定形状?我正在寻找类似的代码ActivePage.addShape(type: person, 100,100, 50,50)
The msdn and visio help documentation comes across as a bit advanced for a beginner, but is it the case that one has to add a shape manually and then give it an id through vba which can be understood and used again. Or do you have to create a global sub/class and then refer to objects that you have given names to.
msdn 和 visio 帮助文档对于初学者来说有点高级,但是否必须手动添加形状,然后通过 vba 给它一个可以理解和再次使用的 id。或者您是否必须创建一个全局子/类,然后引用您已为其命名的对象。
回答by Jon Fournier
The function you need is called Drop. The first argument is dropObject, which can be a reference to another shape, the current selected shape, or a Master object from a Visio stencil.
您需要的功能称为 Drop。第一个参数是 dropObject,它可以是对另一个形状、当前选定形状或 Visio 模具中的主对象的引用。
You can try this out to see how it works:
你可以试试这个,看看它是如何工作的:
Dim ShpObj As Visio.Shape
Set ShpObj = ActivePage.Drop(ActiveWindow.Selection, 100, 50)
So, using ActiveWindow.Selection means Visio will duplicate the selected shape and put it at 100, 50.
因此,使用 ActiveWindow.Selection 意味着 Visio 将复制所选形状并将其放在 100、50。
To get a Master, you need to first find the stencil document that holds the master. Here's an example, putting a Triangle shape from the Basic Shapes block diagram stencil:
要获得母版,您需要首先找到保存母版的模板文档。这是一个示例,从基本形状框图模板中放置一个三角形形状:
Dim ShpObj As Visio.Shape
Set ShpObj = ActivePage.Drop(Application.Documents("BASIC_U.VSS").Masters("Triangle"))
Setting the result of the Drop function to ShpObj means you can refer to it later in code. Otherwise there is a Shapes collection in the Page class that contains all the shapes in the page.
将 Drop 函数的结果设置为 ShpObj 意味着您可以稍后在代码中引用它。否则,Page 类中有一个 Shapes 集合,其中包含页面中的所有形状。
Hopefully that'll make a good start for you in programming in Visio VBA.
希望这将为您在 Visio VBA 中编程提供一个良好的开端。