I have situations where I need to protect certain pages from deletion.
Here is the code:
Private Function Document_QueryCancelPageDelete(ByVal vsoPage As Visio.IVPage) As Boolean
Dim pg As Page
'Function is ran when a page delete command is given
'When True is returned the deletion will be canceled
For Each pg In ActiveDocument.Pages
'
If vsoPage.Name = "PageName" Then 'Name of page
MsgBox "Page Deletion not Allowed", vbOKOnly + vbInformation, "Page Deletion Protector"
Document_QueryCancelPageDelete = True
Exit Function
End If
Next pg
'Document_QueryCancelPageDelete = True
'Always return true so no pages can be deleted
End Function
This is the basic code that is generally used when protecting all pages within a Visio document from deletion.
Here I just added an "IF" function to only protect certain pages.
Cheers.
SubPlanner
You will probably want to remove the for each loop. ;)
Ya, I guess I left it hanging in there as a leftover.
still works good.
I do have a question,
How would I protect the page from being renamed?
SubPlanner
You can't stop it, but you can handle it.
Whenever I set a page name I make sure to update the universal name (NameU) to match the name.
Then I catch the document PageChanged event and if NameU and Name don't match, then I change the Name back yo the NameU. It does mean you will have to provice a mechanism to rename the pages if you allow that.
Also, rather than check for specific pages names, I would add users cells to your pages that you could check instead, makes it more general, e.g. User.NoPageDelete and User.NoPageRename
I am still a bit of a novice when it comes to applying VBA code in Visio. (I have had to much time in Access)
What would the code structure look like to make this work.
Thanks for your help
"SbP"
I double-checked and indeed there is no Protection shapesheet section on a page as far as I can see, so no option to block deletion that way.