Visio Guy

Visio Discussions => Programming & Code => Topic started by: perry59 on November 30, 2010, 10:13:04 PM

Title: remove shape protection
Post by: perry59 on November 30, 2010, 10:13:04 PM
is there a way, via vba, to remove all protection on all shapes on a drawing?
Thanks
Title: Re: remove shape protection
Post by: Paul Herber on December 01, 2010, 03:06:08 AM
The answer has to be yes and no.
Yes, it is possible, with VBA to iterate through all pages, all shapes on those pages (and recurse through grouped shapes) removing all the protection attributes.
However ...



Title: Re: remove shape protection
Post by: perry59 on December 01, 2010, 05:21:44 PM
Gotta love those "yes & no" answers!
I guess I dont need to remove ALL protection...
my problem is I need to modify a bunch of old drawings, meaning mostly a lot of cut&paste and moving things about. Its getting REALLY annoying to paste a group of objects into a new drawing, move the highlighted objects into place and find a bunch of lines  going out into space because someone put protection on and end point or something like that. Then I have to do and "undo" to put the objects back where they were, pick out the lines that had some type of movement protection, unprotect them then move them all where I want them. Its taking way to much time to do a simple task. >:(
Thats why I was hoping I could find a bit of code here that would at least get me a start on a macro to remove some of the protections on every object in a drawing.
Title: Re: remove shape protection
Post by: Paul Herber on December 01, 2010, 05:28:09 PM
Ok, in that case you don't really need VBA at all.
Select all shapes (Control-A), menu Format -> Protection -> None -> OK.
Repeat for each page.
Title: Re: remove shape protection
Post by: perry59 on December 01, 2010, 09:57:46 PM
That was the first thing I tried, it dont work.
I select all on the page, go to menu->format, all the boxes are clear.
I move my selection (or mirror, etc), lines are all wacked out.
I select the wacked line, menu->format and its got protection on x, or y, etc.
The selection may not have protection, but individual items may...
Title: Re: remove shape protection
Post by: Paul Herber on December 01, 2010, 10:12:11 PM
Do you mean that it has a guarded formula?
Title: Re: remove shape protection
Post by: perry59 on December 02, 2010, 04:27:39 PM
I dont even know what a "guarded" formula is, and I dont think there is anyone at my work who is visio enough to do that.
When I select the individual entities, I can remove the protection from them as stated above.
Title: Re: remove shape protection
Post by: Visio Guy on December 02, 2010, 07:34:29 PM
Hmm, I wonder if we have shapes on locked layers, or a protected document?

Bring up the Document Explorer window, right-click on the drawing node and choose Protect Document. Uncheck any items that happen to be checked.
Title: Re: remove shape protection
Post by: wapperdude on December 03, 2010, 02:39:19 AM
Any possiblity that you could provide a Visio file example?
Title: Re: remove shape protection
Post by: perry59 on December 09, 2010, 09:40:42 PM
Sorry I took so long, been doing other chores ::)

The objects are not on locked layers, neither is the document protected.
I will look for something I can send in, will take a while, proprietary stuff.
thanks
Title: Re: remove shape protection
Post by: perry59 on December 16, 2010, 06:06:04 PM
Ok, here's a small sample. (sorry I took so long, been busy!)
If you select everything on the page, then right click and go to protection, it says that the selection is unprotected. If you then move the selection (say out of the page so you can see it more clearly), some of the items move and others dont. If you then select the items that did not move, you find that they have some x or y protection on them. There are no layers in the drawing, and the drawing itself is not protected.
Thats why I'm looking for an "unprotect all" macro, to get rid of these kinds of headaches!
Title: Re: remove shape protection
Post by: wapperdude on December 16, 2010, 08:13:50 PM
The problem is with selecting all shapes.  Visio decides which is the 1st shape selected and then adds the other shapes to the selection group.  If the 1st chosen has no protection issues, then, it would appear that none of the selections have any problems.  Obviously, that isn't necessarily true.

One work around would be to 1st apply all protections to the selection, and then apply no protections.  This will remove any and all protections from the selected group.  You are now free to move about the drawing.

Wapperdude
Title: Re: remove shape protection
Post by: perry59 on December 16, 2010, 09:30:37 PM
A good tip Wapper
thanks for the info  ;D
Title: Re: remove shape protection from a master calendar template
Post by: deweyswak on December 16, 2010, 10:24:54 PM
I need to do the same thing - remove shape protection from a 2010 monthly calendar so I can turn it into a 2011 monthly calendar.  Sadly there isn't a 2011 Visio monthly calendar format on microsoft online yet.  I tried ctrl+A, Format...protection...turn on for all, turn it off.  But still when I try to edit the text box, error msg says "shape protection and/or layer properties prevent complete execution of this command."  I don't want to have to edit the protection for every cell, 365 for the whole year.  There must be a way to remove this for the entire calendar.  ideas?  thanks.
Title: Re: remove shape protection on a calendar
Post by: deweyswak on December 16, 2010, 10:39:36 PM
never mind.  I thought, why go to all this trouble!  I'll just create new 2011 calendars in Visio using the calendar shape. 
Title: Re: remove shape protection
Post by: wapperdude on December 16, 2010, 11:55:46 PM
Regarding calendars -- VisioGuy did this nice variation for 2010.  It might be easily adaptable for 2011, I haven't tried yet.

http://www.visguy.com/2009/12/29/visio-2010-calendar-template/

HTH
Enjoy!
Wapperdude
Title: Re: remove shape protection
Post by: linerate on November 27, 2012, 05:26:39 PM
Good tip and thanks for the explanation as well!
Your answer is still helping others after all this time.

Quote from: wapperdude on December 16, 2010, 08:13:50 PM
The problem is with selecting all shapes.  Visio decides which is the 1st shape selected and then adds the other shapes to the selection group.  If the 1st chosen has no protection issues, then, it would appear that none of the selections have any problems.  Obviously, that isn't necessarily true.

One work around would be to 1st apply all protections to the selection, and then apply no protections.  This will remove any and all protections from the selected group.  You are now free to move about the drawing.

Wapperdude
Title: Re: remove shape protection
Post by: vojo on November 27, 2012, 09:03:18 PM
BTW....same problem with groups and subshapes

select "remove all protections" for group leaves subshapes as they were originally
Title: Re: remove shape protection
Post by: SteveC on September 12, 2013, 08:32:59 PM
After stumbling with this same issue, a work-around I found was to 1) select the set of shapes, 2) group the objects, 3) then delete the group.
Title: Re: remove shape protection
Post by: Jennifer on August 23, 2015, 10:21:07 PM
Quote from: wapperdude on December 16, 2010, 08:13:50 PM
The problem is with selecting all shapes.  Visio decides which is the 1st shape selected and then adds the other shapes to the selection group.  If the 1st chosen has no protection issues, then, it would appear that none of the selections have any problems.  Obviously, that isn't necessarily true.

One work around would be to 1st apply all protections to the selection, and then apply no protections.  This will remove any and all protections from the selected group.  You are now free to move about the drawing.

Wapperdude
Wapperdude,

You are a genius and a life-saver. I have a fairly complex drawing I created myself. My fat fingers kept moving objects I didn't mean to, causing a lot of extra work, some of which I didn't notice until later. I got the bright idea to lock each shape once I got it the way I wanted it. This actually worked fairly well until I wanted to move the whole drawing over a bit to make room some something else. I tried select all shapes and setting all protections off. It didn't work as the OP discovered. So I was left to select each shape individually, a very tedious process.

Finally, I got fed up and searched for a cure. Google, bless it's black corporate heart, found this thread. Your solution worked perfectly.

Thank you, thank you, thank you.

PS: Judging by the number of views of this thread (93,120), you have saved a lot of people a lot of trouble. That's almost 54 views/day since the original post (11/30/10) -- 1,727 days. Amazing.

PPS: And I am appalled at the stupidity of the Microsoft developers. I know I shouldn't be after all these years suffering through the countless bugs and glitches in Word, Excel, Outlook, VBA, etc. What moron thought this was a good implementation?
Title: Re: remove shape protection
Post by: wapperdude on August 24, 2015, 12:01:48 AM
Thanks, Jennifer.  Funny, never really thought about long term implications, nor considered that this might be a wide spread problem.  Whoda thought!   ???
Title: Re: remove shape protection
Post by: Jennifer on August 24, 2015, 12:09:01 AM
Quote from: wapperdude on August 24, 2015, 12:01:48 AM
Thanks, Jennifer.  Funny, never really thought about long term implications, nor considered that this might be a wide spread problem.  Whoda thought!   ???
Well, you saved me at least an hour of locking and unlocking shapes one at a time -- not to mention the toll on my nervous system from all the cursing and the broken glassware hurled against the wall. At one point, I was considering throwing the computer out the window.  >:(
Title: Re: remove shape protection
Post by: wapperdude on August 24, 2015, 01:41:36 AM
 ;D
Title: Re: remove shape protection
Post by: locrian on December 30, 2015, 05:35:49 AM
Another option I tried in my Microsoft Visio Standard 2013 was: File > Options > Advanced (General Section) > Check "Run in Developer Mode".  When you'll get a "DEVELOPER" tab on the Visio main window, select the shape that you want to delete, then inside the "DEVELOPER" tab, there is an "operations" drop down.  Click the "fragment" option.  Then try to delete the shape.  It worked for me.  I had tried to uncheck Protect "From deletion" when you're in the "Protection" option inside the "DEVELOPER" tab, and also tried to check/uncheck to try and trick the option, but no luck with that.
Title: Re: remove shape protection
Post by: sychik on January 23, 2020, 11:51:14 AM
You can recursively unprotect all the shapes in group:

Sub UnprotectSelection()
    Dim i As Long
    For i = 1 To Application.ActiveWindow.Selection.Count
        RecursiveUnprotection Application.ActiveWindow.Selection(i)
    Next
End Sub

Sub RecursiveUnprotection(grp As Shape)
    Dim i As Integer
    For i = 0 To 19 ' grp.Section(visSectionObject).Row(visRowLock).count
        grp.Section(visSectionObject).Row(visRowLock).Cell(i).Formula = 0
    Next i
    If grp.Type = visTypeGroup Then
        Dim shp As Shape
        For Each shp In grp.Shapes
            RecursiveUnprotection shp
        Next shp
    End If
End Sub