Remove/Replace Protection from Shape's Text Field

Started by laelcox, May 03, 2012, 10:42:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

laelcox

Greetings,

I am looking for a hint about how to remove protection from a shape's text field using VBA programming. A previous thread raised a similar topic years ago indicating the possibility (see http://visguy.com/vgforum/index.php?topic=2295.msg10273#msg10273), but the discussion ultimately veered away from a programming solution.  Any hints?

Thanks in advance,

Lael

Paul Herber

The reason the discussion diverged from VBA is that before you can use VBA to remove the protection you need to find out what protection has been applied, find out how to remove it manually first, the conversion to do so in VBA is easy.
Without seeing the details of the exact shape it is impossible to say what to do. There is no one protection for text.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

laelcox

Thank you for the reply. I will try to clarify my situation, as I realize there may be many different scenarios.

My scenario: I want to prevent/enable viewers of my diagram from editing a shape's basic text field (e.g. the field that the formulaic reference "TheText" refers to) using conventional methods (e.g. F2 or double-clicking).  If I deem a user can make edits, I want to be able to quickly run a subroutine unprotecting a certain type of shape for text editing. When that user is done, I will re-protect the text for all other users.  I have checked the box in the Protection dialog box found on the Developer Tab as the default option.  I want to be able to uncheck/check this box with VBA. How might I do that?

Manual Options: Because I am not interested in unprotecting all shapes, using Ctrl-A to unprotect all shapes will not be effective, neither will designating the specified shapes to a layer and selecting the shapes on that layer (too tedious to go through all the pages and specify layer manually; also shapes added in the future may be overlooked and not be designated for that layer.)

Alternatively, I already have code for cycling through all the pages and all the shapes on each page that I have used elsewhere and could easily adapt it to unprotect the text field of a shape. I would be open to and grateful for any guidance you have.




Paul Herber

If that really is all then once you have the shape reference you can do


Shape.CellsSRC(visSectionObject, visRowLock, visLockTextEdit).FormulaU = "0"
to remove protection and
Shape.CellsSRC(visSectionObject, visRowLock, visLockTextEdit).FormulaU = "1"
to protect it.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/