我正在创建一个宏,将菜单按钮添加到选定的Visio形状对象中,因此每当用户右键单击该框时,都会出现一个选项并调用宏。我为对象创建了几个属性,这些属性将由要调用的操作使用。
我可以通过使用ShapeSheet编辑器->View Sections->Actions->手动完成(成功),并将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属性,请给我指正确的一个。
我最终这样做了,而且效果很好。
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
您应该将FormulaU设置为手动设置的内容。也就是说,对于
CALLTHIS("ThisDocument.myFunction",,Prop.IPAddress)
尝试:
vsoShape1.CellsSRC(visSectionAction, intActionRow, visActionMenu).FormulaU = _
"CALLTHIS(""ThisDocument.myFunction"",,Prop.IPAddress)"