简体   繁体   English

如何在 Visio-VBA 中输出形状 ID

[英]How to output shape ID in Visio-VBA

Here is the code in text form in case the image is not loading:这是文本形式的代码,以防图像未加载:

Sub CommandButton1_Click()
   Dim NoIO As String
   Dim shp1 As Visio.Shape
   NoIO = ComboBox1.Value

   If NoIO = "7" Then
      MsgBox shp1.ID
      'Call test(shp1)'
      'Target shape id selected'
      'Change shape data of that shape'
   End If
   Unload Me
End Sub    

Whenever I try to output the ID of a shape, I get the error:每当我尝试输出形状的 ID 时,都会收到错误消息:

Object variable or With block variable not set对象变量或未设置块变量

I cannot change the parameters of the subroutine as I get a procedure declaration mismatch since this code runs after a button click on a user form.我无法更改子例程的参数,因为过程声明不匹配,因为此代码在用户表单上单击按钮后运行。

You have not initialised the shape shp1 .您尚未初始化形状shp1 You have not indicated how you are selecting your shape or why you want to select a shape so I have provided a simple example below.您尚未说明如何选择形状或为什么要选择形状,因此我在下面提供了一个简单示例。

Sub CommandButton1_Click()
   Dim NoIO As String
   Dim shp1 As Visio.Shape
   NoIO = ComboBox1.Value

   Set shp1 = Application.ActivePage.Shapes(1) ' Example only!

   If NoIO = "7" Then
      MsgBox shp1.ID
   End If
   Unload Me
End Sub  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM