Visio Guy

Visio Discussions => Programming & Code => Topic started by: Gustavo on June 25, 2020, 08:24:28 PM

Title: How to disable "Delete" page control?
Post by: Gustavo on June 25, 2020, 08:24:28 PM
Hi all

I'm building a solution and I'm strugling at disabling the controls/context menus for page insert, delete and change name that appears when right click in the name at the bottom of  Visio page. I've disabled the "Duplicate" page with the PageLockDuplicate cell of the page, but I don't know how to disable the other controls. Any toughts? is it possible a work around maybe with a msgbox warning?

Best regards.
Title: Re: How to disable "Delete" page control?
Post by: Hey Ken on July 07, 2020, 11:09:36 PM
Gustavo:

   One thing I've done to stop unauthorized fiddling is to use VBA events to trap the bad behavior using the proper event handler, then simply undo it.  PageChanged traps renaming, DocumentChanged traps inserting pages, CellChanged can trap various Page Setup situations, etc., etc.  You can either use the plain old Undo, or if that's insufficient, capture initial values via the DocumentOpened event, and whenever one of the other events fire, you can check to see if anything important has changed and then just change it back.  I've done this extensively in Excel VBA, and I've had some very frustrated users wondering why they couldn't change anything.  Tee hee.  Might work for your situation too.  The most I've done in Visio is automatically delete any dropped shape I don't approve of.  Lots of frustrated users from that one, too!

   Hope this helps,

   - Ken


P.S. Apologies for the delay in responding.  Been away having fun and ignoring the pandemic.
Title: Re: How to disable "Delete" page control?
Post by: Croc on July 08, 2020, 05:13:50 AM
To block page deletion, it is enough to return TRUE in the Document_QueryCancelPageDelete event handler.

Private Function Document_QueryCancelPageDelete(ByVal Page As IVPage) As Boolean
    Document_QueryCancelPageDelete = True
End Function
Title: Re: How to disable "Delete" page control?
Post by: Gustavo on July 08, 2020, 09:13:46 PM
catch Events, of course! that's a clever solution I hadn't tought of... thank you Ken and Croc!