Delete shape - make tip show.

B

bnk

I want to delete a shape (progarmmatically), and in case when it is
'protected from deletion' show the tip visio normally shows (that
yellow tip with exclamation sign, "shape is protected from deletion").
Exactly what 'Del' key does, but programmatically.

I have tried
selection->Delete,
application->DoCmd(visCmdUFEditClear)

In both cases I get exception when the shape is protected, not the tip.

For now, have found nothing better than writing:
SendMessage(window.WindowHandle32, WM_KEYDOWN, VK_DELETE, 0) ...

Can this be implemented in more elegant way?
 
J

John

Hi bnk,

I hope I've understood you correctly........try something based on the code
below. If the shape is protected, then you need to unprotect it before you
delete it. I've included an option to continue to delete if you want to,
but you could always just change this to a warning msgbox if you really
don't want the user to delete.

Anyway hope this helps

Best regards

John

Sub DeleteProtectedShape()

Dim shp As Visio.Shape

For Each shp In Application.ActiveWindow.Selection
If shp.CellExists("LockDelete", True) = True Then
If shp.Cells("LockDelete").Result(visNumber) <> 0 Then
If MsgBox("The selected shape is protected." & _
" Are you sure you want to delete?", vbYesNo) _
= vbYes Then
shp.Cells("LockDelete").Formula = 0
Else
Exit Sub
End If
End If
End If
shp.Delete
Next shp

End Sub
 
B

bnk

Thank you for reply, John.

But, I don't want to unprotect the shape or show message boxes..

What I want is to simulate the behavior 'Del' key has,
programmatically.

In our solution, the user has a 'delete' command in a shape's context
menu, this command is mapped to ADDON, which does some stuff, and (can)
delete shapes finally.

What I want, is, in case when shape is protected, make Visio show that
nice tip for the user.

Now, this is solved by SendMessage with WM_KEYDOWN to the window. But
this resembles a hack and makes us unhappy.. :)
 
J

John

Sorry, I misunderstood what you were trying to do.

I didn't think that this was functionality that you could access.

Best regards

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

Top