Help... Stop people from renaming a page tab

Started by FlowerGirl, January 29, 2016, 01:02:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

FlowerGirl

I created a basic Visio Org diagram and wanted to use some basic VBA to keep people from renaming the tabs that are in the diagram. I have a fairly basic knowledge of VBA from other Microsoft tools I have used in school but can't seem to get any headway for this situation.

Thanks in advance for any help you can offer  :-*

FlowerGirl

JohnGoldsmith

It sounds like you should be using universal names in your code so that user changes won't interfere with it.  If you're not familiar with local and universal names, many objects in Visio (pages, masters, shapes etc) have two names - a local one that you see in the UI and a 'universal' one that's used behind the scenes.  For a page you'd access the local name with the Page.Name property and for the universal one you'd use Page.NameU.

When a page is first created, it just gets the default 'Page-' + index name and if you look at the names in code, both will return that string.  However the first time a user changes the name via the UI both the local and universal names get set.  Any subsequent user changes will only affect the the local name and the universal one will remain unchanged. 

To review the current state of your page names you could use something like this:

Private Sub LoopPages(ByRef vDoc As Visio.Document)
Dim pag As Visio.Page
For Each pag In vDoc.Pages
    Debug.Print "U - '" & pag.NameU & "'  (L - '" & pag.Name & "')"
Next pag
End Sub


This will list out the two name variations.  Have a go at running this before and after name changes on a new page.

For you case you can reference your pages using the universal name (NameU) safe in the knowledge that users will only be changing local names from there on (unless they also use code of course).

If you really want to lock down the ability of users to change page name then I think you need to catch this with an event and return it to a previous value.  I don't think there's a specific event for this but there may be a scope that you could listen to.  Let me know if that's of interest.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

FlowerGirl

 :D
Thanks so much for your reply. I will attempt to apply your code to my project.
I will get back with you about how it worked (if I can actually make it work).

Chat wit ya soon.   :-*

FlowerGirl

FlowerGirl

I am having a blonde moment.  :(

I can't figure out how to call or launch this code to keep me from renaming during my testing.
I am assuming I can do this maybe on an on open event or something.

I need a little help with where to apply this.  :-\

FlowerGirl

JohnGoldsmith

Well it depends on where you're calling the code from.  If you're trying to call it from the same document then you can use 'ThisDocument' as a reference:

Public Sub CheckNames()
    Call LoopPages(ThisDocument)
    'or
    'Call LoopPages(Application.Documents(2))
End Sub


Private Sub LoopPages(ByRef vDoc As Visio.Document)
Dim pag As Visio.Page
For Each pag In vDoc.Pages
    Debug.Print "U - '" & pag.NameU & "'  (L - '" & pag.Name & "')"
Next pag
End Sub


But if you're in a different document then you'd need to get a refernce to that doc instead.

Does that help?

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

AndyW

You can't stop a page tab from being renamed, but you can handle it.

Whenever I create a page I always set a page name to make sure the universal name (NameU) is updated, i.e. NameU and Name match.

Then I catch the document PageChanged event and if NameU and Name don't match, then I change the Name back to the NameU. It does mean you will have to provide a mechanism to rename the pages if you want allow that.

If it's only certain pages that can't be renamed, rather than check names I would as a pagesheet cell such as User.NoPageRename to identify the page that you don't want to be renamed.
Live life with an open mind

FlowerGirl

So if I renamed a page from "NameTest" to "NameTest2" how could this code tell me that I should not be changing the name or stop me from doing so.
Maybe in a message box or something.

I can understand the code once I see it and read it, but I am having a hard time getting it do act as a block to keep me from changing the name.

Thanks for your patience with this newbie.
FlowerGirl



AndyW

Some code and I have attached a working example.

Private Sub Document_PageChanged( _
    ByVal vsoPage As IVPage)

    With vsoPage
   
        If .PageSheet.CellExistsU("User.NoPageRename", 0) Then
   
            If .PageSheet.CellsU("User.NoPageRename").ResultInt(0, 0) = 1 Then
       
                If .NameU <> .Name Then
                    .Name = .NameU
                End If
               
            End If
       
        End If
       
    End With

End Sub
Live life with an open mind

FlowerGirl

WOW, that's it.   ;D  ;D  ;D

Your code did the trick, now I can keep the minions from running amuck.

Thanks so much for your help.


FlowerGirl  )00(

FlowerGirl

John, I wanted to thank you also for your section of code that allows me to see the "Hidden" NameU of each page.

I am slowly learning about the Visio behind the Visio.

Thanks for your help.

FlowerGirl  :-*

AndyW

We are all friendly here and pleased to help anyone learn
Live life with an open mind