本帖最后由 hessen 于 2020-9-16 11:59 编辑
明细表一列中,将改列设置了可编辑,而部分带有函数公式的行则也可以被编辑,可以通过VBA将带有函数公式的单元格锁定,不可编辑。其他没有公式的单元格正常编辑。将下面的代码写入VBA打开事件中,其中T_671是要判断的区域,一般为明细表区域。
- ActiveWorkbook.WorkbookSet.GetLock()
- Dim MyRange As IRange
- For Each MyRange In Range("T_671")
- If MyRange.HasFormula Then
- MyRange.Locked = True
- End If
- Next
- ActiveWorkbook.WorkbookSet.ReleaseLock()
复制代码 如果要按钮执行可以按下面的方法写
- Public Sub ButtunClick(sender As Object, e As SpreadsheetGear.Windows.Controls.ShapeActionEventArgs) Implements Interfaces.IExcelWorkBook.ButtunClick
- ActiveWorkbook.WorkbookSet.GetLock()
- Dim MyRange As IRange, BtName As String
- BtName = e.Shape.Name
-
- ActiveWorkbook.WorkbookSet.ReleaseLock()
- If BtName = "Button 1" Then
- For Each MyRange In Range("T_671")
- If MyRange.HasFormula Then
- MyRange.Value = BtName
- MyRange.Locked = True
- End If
- Next
- End If
- End Sub '按钮/标签点击事件
复制代码
|
|
hessen