以编程方式将菜单操作添加到Visio

时间:2014-11-07 22:36:27

标签: vba visio shapesheet

我正在创建一个宏来将菜单按钮添加到选定的Visio形状对象,因此每当用户右键单击该框时,都会出现一个选项并调用一个宏。我为对象创建了一些属性,这些属性将被要调用的动作使用。

我可以使用 ShapeSheet 编辑器手动完成( SUCCESSFULLY ) - >查看部分 - >行动 - >并使用Action值配置操作  =CALLTHIS("ThisDocument.myFunction",,Prop.IPAddress)

sub myFunction (shpObj as Visio.shape, strIPAddress as String) 
'working code with the functionsI want it to do. here I use the strIPAddress passed as an argument

我尝试做的是通过创建一个相同的宏来实现自动化:

    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属性,请指出正确的属性。

2 个答案:

答案 0 :(得分:0)

您应该将FormulaU精确地设置为您手动设置的内容。那就是

CALLTHIS("ThisDocument.myFunction",,Prop.IPAddress)

尝试:

vsoShape1.CellsSRC(visSectionAction, intActionRow, visActionMenu).FormulaU = _
    "CALLTHIS(""ThisDocument.myFunction"",,Prop.IPAddress)"

答案 1 :(得分:0)

我最终这样做了,它运作得很好。

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