Visio Guy

Visio Discussions => Programming & Code => Topic started by: PinPinPoola on August 19, 2021, 03:48:15 PM

Title: VBA Code to enable and disable shape protections for all shapes on all pages?
Post by: PinPinPoola on August 19, 2021, 03:48:15 PM
Hello,

I hope someone can help me please. I need to enable all protections for all shapes on 170+ pages of a Visio diagram file and I fear I will get Repetitive Strain Injury if I try this manually.

Would anyone have the VBA code to highlight/select all shapes on a page, enable all protections and then repeat for all foreground pages?

My right wrist would be eternally grateful, as would the rest of me for any help/advice.

Thx
Pin

Title: Re: VBA Code to enable and disable shape protections for all shapes on all pages?
Post by: Surrogate on August 19, 2021, 04:11:11 PM
Hi, from Russia !
Quote from: PinPinPoola on August 19, 2021, 03:48:15 PM
Would anyone have the VBA code to highlight/select all shapes on a page, enable all protections and then repeat for all foreground pages?
I haven't this code before, just write this code in few minutes
Sub PinPinPoola()
Dim pg As Page
Dim shp As Shape
Dim PS As Section
Dim pr As Row
Dim pc As Cell
For Each pg In ActiveDocument.Pages
For Each shp In pg.Shapes
Set PS = shp.Section(visSectionObject)
Set pr = PS.Row(visRowLock)
For r = 0 To pr.Count - 1
Set pc = pr.Cell(r)
pc.FormulaU = "0"
Next
Debug.Print shp.Name & " disabled"
Next
Debug.Print "all shapes at page" & pg.Name & " are disabled"
Next
End Sub
Title: Re: VBA Code to enable and disable shape protections for all shapes on all pages?
Post by: PinPinPoola on August 19, 2021, 08:22:43 PM
Hello @Surrogate

Thank you for your help.

I have just tested this and it works for basic line drawn shapes, but when I use a server shape from HPE, it fails with a "Run-time error '-2032466648 (86db0528)': Cell is guarded."

Any ideas?

Thx
Pin
Title: Re: VBA Code to enable and disable shape protections for all shapes on all pages?
Post by: Surrogate on August 19, 2021, 09:05:35 PM
Quote from: PinPinPoola on August 19, 2021, 08:22:43 PM
"Run-time error '-2032466648 (86db0528)': Cell is guarded."

Any ideas?
Try change row pc.FormulaU = "0"
to pc.FormulaForce = "0"
Title: Re: VBA Code to enable and disable shape protections for all shapes on all pages?
Post by: PinPinPoola on August 20, 2021, 04:08:45 PM
Hello @Surrogate

That worked - Thank you so much!!!

Have a great weekend.

Pin
Title: Re: VBA Code to enable and disable shape protections for all shapes on all pages?
Post by: OldSchool1948 on August 22, 2021, 06:36:25 PM
You also use put the equal sign before the zero.                 

pc.FormulaU = "=0"