Update Action Rows with Automation Fails

M

Morton

I'm using Visio 2003 and trying to create a shape with
automation. Either one of these alternatives would be
fine but they both fail. Does anyone have any idea why?

I can create the Action Rows manually so that's not the
issue. Here is the code:

Sub Macro2()

Dim sh As Visio.Shape

ActiveWindow.DeselectAll
Set sh = ActivePage.DrawRectangle(4, 4, 6, 4.5)
With sh
.AddSection visSectionAction
'
' Alternative A - fails with Cannot Create
Object
'
.AddRow visSectionAction, 1, 0
.CellsSRC(visSectionAction, 1,
visActionMenu).FormulaU = "Choose Domain" ' fails here
.CellsSRC(visSectionAction, 1,
visActionAction).FormulaU = "CALLTHIS
(""ChangeProcessDomain"",)"
'
' Alternative B - fails with #NAME?
'
.AddNamedRow visSectionAction, "ChooseDomain", 0
.CellsU("Actions.ChooseDomain.Menu").FormulaU
= "Choose Domain" ' fails here
.CellsU("Actions.ChooseDomain.Menu").FormulaU
= "CALLTHIS(""ChangeProcessDomain"",)"
End With

End Sub
 
M

Mark Nelson [MS]

Two problems:

The row you create with AddRow has an index of 0. CellsSRC is trying to set
a formula in row 1, which generates the error you describe. To be sure of
the row, save the return value from the AddRow call and use that as your row
index.

When setting a Formula, remember to include the appropriate set of quotation
marks. When you assign a string to a variable in Visual Basic, the
quotation marks tell VB that you have a string. The quotes are not part of
the string itself. For Visio, your formula must either be an expression to
be evaluated or a string wrapped in quotes. Therefore, to assign Choose
Domain as a string value, you need three quotes in a row: """Choose
Domain""" It may be more understandable to write Chr(34)+"Choose
Domain"+Chr(34).
 
M

Morton

Much obliged.

The extra quotes were confusing since when you enter the
values directly in the Shapesheet, it takes the string
without the quotes (obviously inserting quotes
automatically.)

Subject #2.

The built-in ability to set the context menu is rather
neat. However, if I prefer to use cascading context
menu's would there be any problem setting the context
menu myself using the Office CommandBar code. If so, how
would you suggest I find the context menu(s) for shapes.
Is there actually more than one context menu or is it
just one menu that is constantly reset depending on which
shape gets the focus?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top