我试图阻止用户直接键入选中的单元格,我已经阻止单元格双击时进入编辑模式。但是,我仍然需要阻止它们在被选中时键入单元格,为此我想要使用VBA禁用直接编辑模式。有谁知道如何做到这一点?
答案 0 :(得分:0)
您可以使用内置功能保护单元格,例如:
Option Explicit
Sub MyProtect()
Dim wb As Workbook
Dim sh As Worksheet
Dim rn As Range
Set wb = ThisWorkbook
Set sh = wb.Sheets("Sheet1")
'Unprotect sheet.
sh.Unprotect
'Unlock all cells on the sheet.
sh.Cells.Locked = False
'Lock the chosen cell.
Set rn = sh.Range("A1")
rn.Locked = True
'Protect the worksheet.
sh.Protect
'Or protect with password.
'sh.Protect Password:="test"
End Sub