Vba 以编程方式将菜单操作添加到Visio
我正在创建一个宏,用于将菜单按钮添加到选定的Visio shape对象,因此每当用户右键单击该框时,将显示一个选项并调用宏。我为对象创建了几个属性,将由要调用的操作使用 我可以使用ShapeSheet编辑器->查看部分->操作->并使用操作值配置操作,手动(成功地)Vba 以编程方式将菜单操作添加到Visio,vba,visio,shapesheet,Vba,Visio,Shapesheet,我正在创建一个宏,用于将菜单按钮添加到选定的Visio shape对象,因此每当用户右键单击该框时,将显示一个选项并调用宏。我为对象创建了几个属性,将由要调用的操作使用 我可以使用ShapeSheet编辑器->查看部分->操作->并使用操作值配置操作,手动(成功地) =CALLTHIS(“ThisDocument.myFunction”、Prop.IPAddress) 我试图通过创建一个宏来自动执行此操作,该宏执行相同的操作: Public Sub AddActionToShape()
=CALLTHIS(“ThisDocument.myFunction”、Prop.IPAddress)
我试图通过创建一个宏来自动执行此操作,该宏执行相同的操作:
Public Sub AddActionToShape()
Dim vsoShape1 As Visio.Shape
Dim intActionRow As Integer
'Performs this action to the selected item
Set vsoShape1 = Application.ActiveWindow.Selection(1)
'create row in the action section (http://office.microsoft.com/en-gb/visio-help/HV080902125.aspx)
intActionRow = vsoShape1.AddRow(visSectionAction, visRowLast, visTagDefault)
'add action to the row (http://msdn.microsoft.com/en-us/library/office/ff765539(v=office.15).aspx)
'HERE IS THE PROBLEM
**vsoShape1.CellsSRC(visSectionAction, intActionRow, visActionAction).FormulaU = """myFunction(vsoShape1, vsoShape1.Prop.IPAddress)"""**
vsoShape1.CellsSRC(visSectionAction, intActionRow, visActionMenu).FormulaU = """My Function"""
End Sub
我的问题:
传递参数时,我应该在公式上加什么值来引用宏中定义的子程序。如果我不应该使用此FormulaU属性,请为我指出正确的属性。您应该将FormulaU完全设置为手动设置的内容。就是
CALLTHIS("ThisDocument.myFunction",,Prop.IPAddress)
尝试:
最后我就这样做了,效果很好
Dim formula As String
formula = "=CALLTHIS([MODULE],,[ARG1],[ARG2])"
formula = Replace(formula, "[MODULE]", Chr(34) & "ThisDocument.myFunction" & Chr(34))
formula = Replace(formula, "[ARG1]", "Prop.IPAddress")
formula = Replace(formula, "[ARG2]", "Prop.Username")
'After the formula has been created, apply it to the row
shape.CellsSRC(visSectionAction, rowBeingEdited, visActionAction).formula = formula
我已经在addin(在visualstudio中)中添加了这段代码,当我单击上下文菜单选项时,不会调用该方法。你能帮忙吗?
vsoShape1.CellsSRC(visSectionAction, intActionRow, visActionMenu).FormulaU = _
"CALLTHIS(""ThisDocument.myFunction"",,Prop.IPAddress)"
Dim formula As String
formula = "=CALLTHIS([MODULE],,[ARG1],[ARG2])"
formula = Replace(formula, "[MODULE]", Chr(34) & "ThisDocument.myFunction" & Chr(34))
formula = Replace(formula, "[ARG1]", "Prop.IPAddress")
formula = Replace(formula, "[ARG2]", "Prop.Username")
'After the formula has been created, apply it to the row
shape.CellsSRC(visSectionAction, rowBeingEdited, visActionAction).formula = formula