#1
|
|||
|
|||
Enable Delete Row macro when document is protected
Hello, could you please help me adjust my DeleteRow macro to work when the document is protected? I have the AddRow working when the document is protected. I've recorded shortcuts ALT A and D for add and delete to use while protected. Thank you!
|
#2
|
||||
|
||||
You need to check your shortcuts as they don't work. However to delete from a protected document, you must remove the protection first, just as in your macro to add rows, and reapply it afterwards e.g.
Code:
Private Sub Delete_Click() Dim vProtectionType As Variant, strPassword As String vProtectionType = ActiveDocument.ProtectionType If vProtectionType <> wdNoProtection Then strPassword = "" 'Insert password here ActiveDocument.Unprotect Password:=strPassword End If Application.ScreenUpdating = False Dim Tbl As Table, cel As Cell, r As Long, x As Long Dim bDel As Boolean, CCtrl As ContentControl With ActiveDocument For Each Tbl In .Tables For r = Tbl.Rows.Count To 1 Step -1 With Tbl.Rows(r) If Len(.Range.Text) = .Cells.Count * 2 + 2 Then .Delete Else bDel = True For Each cel In .Cells If Len(cel.Range.Text) > 2 Then If .Range.ContentControls.Count = 0 Then bDel = False: Exit For Else For Each CCtrl In .Range.ContentControls If CCtrl.ShowingPlaceholderText = False Then bDel = False: Exit For End If x = x + Len(CCtrl.Range.Text) Next If x + 2 <= Len(cel.Range.Text) Then bDel = False: Exit For End If End If End If Next cel If bDel = True Then Tbl.Rows(r).Delete End If End With Next r Next Tbl End With If vProtectionType > -1 Then ActiveDocument.Protect Type:=vProtectionType, Password:=strPassword End If Set cel = Nothing: Set Tbl = Nothing Application.ScreenUpdating = True End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
This is perfect and exactly what I was hoping for. Thank you!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Could you help me create a control button/check box to enable user to delete a row? | baes10 | Word Tables | 2 | 12-11-2017 10:10 AM |
Macro to replace Image, Numbers in Table and in multiple protected word document | balaji | Word VBA | 10 | 03-24-2016 02:11 AM |
Macro to Unprotect password protected document | pooklet | Word | 2 | 12-08-2014 01:32 AM |
Enable watermark in a protected document | erickalves05 | Word | 2 | 10-17-2014 10:26 AM |
Enable Styles in Protected Document | la_gillespie25 | Word | 1 | 05-13-2013 11:28 AM |