MS Visio 使用 VBA 拖放自定义形状
MS Visio Drop a custom shape using VBA
我似乎无法弄清楚如何使用 VBA 放置形状。
我想要做的是:用户打开一个用户窗体并在文本框中输入一些内容。单击命令按钮时,我想从自定义模板(即 shapes.vssx)加载形状(即资源),将用户条目写入 ShapeData(即在 Props.Name 中写入名称字符串),然后将它放在 sheet 的某处。我知道我必须使用 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
其中 returns 类型不匹配。我错过了什么?
您希望删除 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
我似乎无法弄清楚如何使用 VBA 放置形状。
我想要做的是:用户打开一个用户窗体并在文本框中输入一些内容。单击命令按钮时,我想从自定义模板(即 shapes.vssx)加载形状(即资源),将用户条目写入 ShapeData(即在 Props.Name 中写入名称字符串),然后将它放在 sheet 的某处。我知道我必须使用 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
其中 returns 类型不匹配。我错过了什么?
您希望删除 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