Doug Mutzig
Board Regular
- Joined
- Jan 1, 2019
- Messages
- 57
- Office Version
- 365
- Platform
- Windows
I am working on protecting my workbook but I have many backend macros and macros tied to buttons. Research found that the recommended way to protect worksheets and still allow macros to work is to use the userinterfaceonly = True property.
i have been testing each of my worksheets to make sure I have the right areas unlocked and that things work. To do this I have the VB window open and type in:
to protect the worksheet and test. However, I am unable to use any of my macro buttons for some reason.
Two general buttons are:
1. Add Row using this code
2. Delete Selected Row(s) using the below code
Is there something I am missing with the userinterfaceonly=true usage? Is there a reason my buttons would not work?
i have been testing each of my worksheets to make sure I have the right areas unlocked and that things work. To do this I have the VB window open and type in:
Code:
activesheet.protect userinterfaceonly:=True
Two general buttons are:
1. Add Row using this code
Code:
ActiveSheet.ListObjects(1).ListRows.Add
Code:
Sub GlobalRemoveSelectedTableRows()
Dim loTtest As ListObject
Dim loSet As ListObject
Dim c As Range
Dim arrRows() As Variant
Dim arrTemp() As Variant
Dim xFind As Variant
Dim iCnt As Long
Dim sMsg As String
Erase arrRows()
iCnt = 1
For Each c In Selection.Cells
If Not c.ListObject Is Nothing Then
If loSet Is Nothing Then
Set loSet = c.ListObject
Else
If c.ListObject <> loSet Then
'different table
MsgBox "You have more than one table selected.", vbInformation, "ERROR!"
GoTo MyExit
End If
End If
If iCnt = 1 Then
ReDim arrRows(1 To iCnt)
arrRows(iCnt) = c.Row - loSet.HeaderRowRange.Row
iCnt = iCnt + 1
Else
On Error Resume Next
xFind = 0
xFind = WorksheetFunction.Match(c.Row - loSet.HeaderRowRange.Row, arrRows(), 0)
If xFind = 0 Then
ReDim Preserve arrRows(1 To iCnt)
arrRows(iCnt) = c.Row - loSet.HeaderRowRange.Row
iCnt = iCnt + 1
End If
Err.Clear
On Error GoTo 0
End If
Else
'a cell is not in a table
MsgBox "Your selection is all or partially outside of a table.", vbInformation, "ERROR!"
GoTo MyExit
End If
Next c
Call SortArray(arrRows())
sMsg = "Are you sure you want to delete " & UBound(arrRows) & " rows from '" & loSet.Name & "'?"
If MsgBox(sMsg, vbYesNo + vbDefaultButton2, "CONTINUE?") <> vbYes Then Exit Sub
For iCnt = UBound(arrRows) To LBound(arrRows) Step -1
loSet.ListRows(arrRows(iCnt)).Delete
Next iCnt
Exit Sub
MyExit:
End Sub
Is there something I am missing with the userinterfaceonly=true usage? Is there a reason my buttons would not work?