Office中国论坛/Access中国论坛

标题: [求助][如何用一个控件做保护工作表? [打印本页]

作者: secowu    时间: 2005-6-22 23:49
标题: [求助][如何用一个控件做保护工作表?
新建了个控件COMMAND1

Private Sub CommandButton1_Click()

Dim i As Long

Do While i < 31 '假设工作表有31个,并且全部以数字命名,1,2,3,...31

i = i + 1

Sheets(i).Select

    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _

        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _

        AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _

        :=True, AllowInsertingHyperlinks:=True, AllowSorting:=True, _

        AllowFiltering:=True, AllowUsingPivotTables:=True

   Loop

   End Sub

这样行吗?
作者: secowu    时间: 2005-6-23 16:41
问题解决了。是这样的,参考了大师的做法:Sub unprotectPW() '解除工作表保护,如果有密码则加参数

Dim a As Integer

    For a = 1 To Sheets.Count

    Sheets(a).unprotect 'Password:=123456

    Next a

End SubSub ProtectPW() '给工作表加保护,并且决定是否加密码

Dim a As Integer

    For a = 1 To Sheets.Count

    Sheets(a).protect DrawingObjects:=False, Contents:=True, Scenarios:= _

        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _

        AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _

        :=True, AllowInsertingHyperlinks:=True, AllowSorting:=True, _

        AllowFiltering:=True, AllowUsingPivotTables:=True

          'Password:=123456

    Next a

End Sub问题二:     如何,设个变量,有个对话的方式,可以让用户自定义密码,进行工作表保护呢?就在这个例子里实现?




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