Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2017, 05:39 PM
baes10 baes10 is offline Enable Delete Row macro when document is protected Windows 7 64bit Enable Delete Row macro when document is protected Office 2007
Advanced Beginner
Enable Delete Row macro when document is protected
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default 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!
Attached Files
File Type: docm Skin Report.docm (118.2 KB, 10 views)
Reply With Quote
  #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,101
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 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
  #3  
Old 12-19-2017, 10:04 AM
baes10 baes10 is offline Enable Delete Row macro when document is protected Windows 7 64bit Enable Delete Row macro when document is protected Office 2007
Advanced Beginner
Enable Delete Row macro when document is protected
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default

This is perfect and exactly what I was hoping for. Thank you!
Reply With Quote
Reply

Thread Tools
Display Modes


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 01:44 PM.


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