Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-19-2017, 12:30 AM
gmayor's Avatar
gmayor gmayor is offline Enable Delete Row macro when document is protected Windows 10 Enable Delete Row macro when document is protected Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
 



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
Enable Delete Row macro when document is protected Macro to replace Image, Numbers in Table and in multiple protected word document balaji Word VBA 10 03-24-2016 02:11 AM
Enable Delete Row macro when document is protected Macro to Unprotect password protected document pooklet Word 2 12-08-2014 01:32 AM
Enable Delete Row macro when document is protected Enable watermark in a protected document erickalves05 Word 2 10-17-2014 10:26 AM
Enable Delete Row macro when document is protected Enable Styles in Protected Document la_gillespie25 Word 1 05-13-2013 11:28 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft