Office中国论坛/Access中国论坛

标题: 保护工作表单元格的一个方法 [打印本页]

作者: tmtony    时间: 2004-7-1 07:37
标题: 保护工作表单元格的一个方法
原创:Designed by Tommy Flynn

翻译: tmtony


' 这个例程搜索工作表中所有单元格,如果单元格没有公式\日期或文本,而且单元格

'是数字,则解锁单元格,且字体为蓝色,其它锁定单元格,字体为黑色

'实现在工作表保护后,可以修改数字,而不能修改文本 日期和公司


Sub Set_Protection()

On Error GoTo errorHandler

Dim myDoc As Worksheet

Dim cel As Range

Set myDoc = ActiveSheet

myDoc.UnProtect

For Each cel In myDoc.UsedRange

    If Not cel.HasFormula And _

    Not TypeName(cel.Value) = "Date" And _

    Application.IsNumber(cel) Then

        cel.Locked = False

        cel.Font.ColorIndex = 5

    Else

        cel.Locked = True

        cel.Font.ColorIndex = xlColorIndexAutomatic

    End If

Next

myDoc.Protect

Exit Sub

errorHandler:

MsgBox Error

End Sub

作者: joyark    时间: 2011-7-3 00:10
受益非浅




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3