DoCmd Error - Strange Behaviour?

J

John

Hi there, this follows on from some advice from Mark Nelson in an earlier
post ("Reset Dynamic Connectors").

I'm trying to set a dynamic connector to return to its original curved state
using Application.DoCmd(visCmdConnectorEffectCurved).

The trouble is I'm getting a "Requested operation is presently disabled"
error on this line. You then click on Debug and press F8 to execute the
line again and it suddenly works ok!

Any clues as to what's going on and how I can avoid this error?

(I'm using Visio Standard v11)

The code is as follows:

Dim vsoSelection1 As Visio.Selection
Set vsoSelection1 = pag.CreateSelection(visSelTypeByLayer, _
visSelModeSkipSuper, "Connector")
Application.ActiveWindow.Selection = vsoSelection1
Application.DoCmd (1945) 'visCmdConnectorEffectCurved

Best regards

John
 
J

JuneTheSecond

It is really strange.
May be a bug in Visio.
DoCmd fails, but next would do.
objShape.CellsSRC(visSectionObject, visRowShapeLayout,
visSLOLineRouteExt).FormulaU = 2
objShape.CellsSRC(visSectionObject, visRowShapeLayout,
visSLORouteStyle).FormulaU = 1
 
J

JuneTheSecond

So, next would be simpler;
Set vsoSelection1 = ActivePage.CreateSelection(visSelTypeByLayer,
visSelModeSkipSuper, "connector")
UndoScopeID1 = Application.BeginUndoScope("test")
For Each shp In vsoSelection1
shp.Cells("ConLineRouteExt") = 2
shp.Cells("ShapeRouteStyle") = 1
Next
Application.EndUndoScope UndoScopeID1, True
 
J

John

Hi June,

I'm afraid this doesn't work. I should have been clearer about the problem:
It's not to reset from a straight to a curved connector, but to reset after
the "eccentricity handle" (visio's term) of a curved connector has been
altered. But I'm still wondering why the original code works sometimes but
not others?

Best regards

John
 
J

JuneTheSecond

When you hide the Visio window once behind other application,
such as Internet Explorer , DoCmd works.
Anyway it must be a kind of bug in Visio.
 
J

JuneTheSecond

I reccomend you to try the code at the third post.
But if you stlongly wish DoCmd, next would be
one of the answer.
To use this code, you would open another new
drawing as a dummy at the back of main drawing.
And, you would be prepare two UserForms with
one Command Button each.
When you run macro test1, UserForm1 appears,
then press button, and then userform2 appears,
press button again.
Sub test1()
Dim vsoLayer As Layer
Dim vsoSelection1 As Visio.Selection
Set vsoLayer = ActivePage.Layers("connector")
Set vsoSelection1 = ActivePage.CreateSelection(visSelTypeByLayer,
visSelModeSkipSuper, vsoLayer)
Application.ActiveWindow.Selection = vsoSelection1
Application.Windows(2).Activate
UserForm1.Show vbModeless
End Sub
Private Sub CommandButton1_Click()
Application.Windows(1).Activate
UserForm2.Show vbModeless
Unload Me
End Sub
Private Sub CommandButton1_Click()
Application.DoCmd (1945) 'visCmdConnectorEffectCurved
Unload Me
End Sub
 
M

Mark Nelson [MS]

On other thing to try is to call DoEvents in between assigning the Selection
and invoking DoCmd. That often is a workaround for things that work when
stepping through code but not when executing it outright.
 
J

John

Hello June,

Well thanks very much for this.

The shp.Cells("ConLineRouteExt") = 2 / shp.Cells("ShapeRouteStyle") = 1
doesn't appear to work I'm afraid and although I like the idea of the code
below I've really got to cycle through the pages so if I've got to click the
cmd button each time then I may as well use the manual method.

Thank you very much for you time though.

Best regards

John
 
J

John

Hi Mark,

I had a go with the DoEvents function, but no joy I'm afraid.

The error is very inconsistant really and appears both in step through and
when normal executing.

Back to the manual method I suppose!

Thanks

John
 

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

Similar Threads


Top