我似乎无法弄清楚如何使用VBA绘制形状。
我想要做的是:用户打开一个用户窗体,然后在文本框中输入内容。当单击命令按钮时,我想从自定义模具(即shapes.vssx)加载一个Shape(即ressource),将用户条目写入ShapeData(即在Props.Name中写一个Name字符串),然后将其拖放到工作表。我知道我必须使用Shape.Drop方法,但是如何引用要用于创建新形状的特定主形?
到目前为止,我正在对此进行尝试
Private Sub CommandButton1_Click()
Dim shp As Visio.Shape
Dim page As Visio.page
Set page = Application.ActiveWindow.page
Set shp = Application.Documents.Item("shapes.vssx").Masters.ItemU("ressource")
page.Drop shp, 1, 1
End Sub
哪个返回类型不匹配。我想念什么?
答案 0 :(得分:3)
您要删除Master
而不是Shape
,因此请尝试修改此代码(未经测试):
Private Sub CommandButton1_Click()
Dim mst as Visio.Master
Dim shp As Visio.Shape
Dim pag As Visio.page
Set pag = Application.ActiveWindow.Page
Set mst = Application.Documents.Item("shapes.vssx").Masters.ItemU("ressource")
'You might also want to add some checks that the target document and then master exist
Set shp = pag.Drop(mst, 1, 1)
End Sub