冠军欧洲2010
发表于 2012-3-7 22:43
H:18 冠军欧洲2010
libenwen2011
发表于 2012-3-7 22:47
16组:libenwen2011
(UID: 514207)
libenwen2011
发表于 2012-3-7 22:49
16组:libenwen2011
(UID: 514207)
libenwen2011
发表于 2012-3-7 22:52
libenwen2011 发表于 2012-3-7 22:47 static/image/common/back.gif
16组:libenwen2011
(UID: 514207)
不小心设置了权限,重新发一个。
XUEWU止境
发表于 2012-3-7 23:20
C08 XUEWU止境
第1题:
Sub 批量添加保护()
Dim x As Integer
With Worksheets("密码表")
For x = 2 To Application.WorksheetFunction.CountA(.Columns(1))
Worksheets(.Cells(x, 1).Value).Protect Password:=.Cells(x, 2)
Next
End With
End Sub
第2题:
Sub 隐藏工作表()
Dim i As Integer
For i = 1 To Sheets.Count
If Sheets(i).Name <> "主界面" Then
Sheets(i).Visible = 0
End If
Next i
End Sub
第3题:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Not Sh Is Worksheets("主界面") Then Worksheets("主界面").Activate
End Sub
Sub 只看主界面工作表()
Application.EnableEvents = True
End Sub
dsjohn
发表于 2012-3-8 00:14
作业做完,谢谢批改!!!!
linmm
发表于 2012-3-8 01:30
Option Explicit
Dim x As Integer
Sub 隐藏工作表()
Sheets(Array("密码表", "sheet2", "sheet3", "sheet4", "sheet5")).Visible = 0
End Sub
Sub 取消隐藏工作表()
For x = 1 To 5
Sheets(x).Visible = -1
Next x
End Sub
Sub 批量添加保护()
With Sheets("密码表")
For x = 2 To 5
If .Range("a" & x) = "Sheet" & x Then
Sheets("Sheet" & x).Protect Password:=.Range("b" & x)
End If
Next x
End With
End Sub
Sub 判断工作表是否被保护()
For x = 1 To 6
If Sheets(x).ProtectContents = True Then
MsgBox "Sheets" & x & "工作表被保护"
Else
MsgBox "Sheets" & x & "工作表未被保护"
End If
Next x
End Sub
Sub 取消批量保护()
For x = 2 To 5
Sheets("Sheet" & x).Unprotect Password:=Range("b" & x)
Next x
End Sub
Private Sub Worksheet_Activate()
If ActiveSheet.Name <> "主界面" Then
Sheets("主界面").Select
End If
End Sub
1982zyh
发表于 2012-3-8 10:12
Option Explicit
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name <> "主界面" Then
Sheets("主界面").Select
End If
End Sub
Option Explicit
Sub 隐藏工作表()
Dim i As Integer
For i = 1 To Sheets.Count
If Sheets(i).Name <> "主界面" Then
Sheets(i).Visible = 0
End If
Next i
End Sub
Sub 保护()
Dim X As Integer
Dim m As Integer
Dim str1 As String
Dim str2 As String
Sheets("密码表").Select
X = ActiveSheet.UsedRange.Rows.Count
For m = 2 To X
If Cells(m, 1) <> "" Then
str1 = Cells(m, 1)
str2 = Cells(m, 2)
Sheets(str1).Protect Password:=str2
End If
Next m
End Sub
liuho1
发表于 2012-3-8 10:38
1、
Sub 添加保护()
Dim a, b, c, d As Integer
With Sheets("密码表")
a = .Range("B2")
b = .Range("B3")
c = .Range("B4")
d = .Range("B5")
End With
Sheets("sheet2").Protect Password:=a
Sheets("sheet3").Protect Password:=b
Sheets("sheet4").Protect Password:=c
Sheets("sheet5").Protect Password:=d
End Sub
2、
Sub 隐藏工作表()
Sheets(Array("sheet2", "sheet3", "sheet4", "sheet5", "密码表")).Visible = 0
End Sub
3、
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sheets("主界面").Activate
End Sub
梅一枝
发表于 2012-3-8 11:57
A06:梅一枝
第一题代码:
Sub vba顺序的()
Dim x As Integer
With Sheets("密码表")
For x = 2 To 5
If Sheets(x) Is Sheets(2) Then
Sheets(2).Protect Password:=.Range("B" & x)
ElseIf Sheets(x) Is Sheets(3) Then
Sheets(3).Protect Password:=.Range("B" & x)
ElseIf Sheets(x) Is Sheets(4) Then
Sheets(4).Protect Password:=.Range("B" & x)
ElseIf Sheets(x) Is Sheets(5) Then
Sheets(5).Protect Password:=.Range("B" & x)
End If
Next x
End With
End Sub
Sub 顺序()
Dim x As Integer
With Sheets("密码表")
For x = 2 To 5
Worksheets(.Range("a" & x).Value).Protect Password:=.Range("B" & x)
Next x
End With
End Sub
补充:我指定的第二个代码;(目前水平不足,有时候还绕不开 哪个表名代表哪个工作表,为保险起见,写了2个代码,让老师费心了。)
第二题代码:
Sub 隐藏工作表()
Dim x As Integer
For x = 1 To Sheets.Count
If Not Sheets(x) Is Sheets(6) Then
Sheets(x).Visible = 0
End If
Next x
End Sub
Sub 隐藏表()
Sheets(Array("密码表", "sheet5", "sheet4", "sheet2", "sheet3")).Visible = 0
End Sub
补充说明:我指定的第一个代码,(同样的,第二题也用了2个方法写的,可是第二个代码隐藏可以,取消隐藏就报错。不知道问题在哪里,还请老师指点)
第三题代码:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sheets(6).Select
End Sub
补充说明:虽然代码字符少,卡壳的时间最长,用哪个事件程序就试了5.6次,还是不太清楚,什么时候用什么事件。继续看视频加深记忆。老师辛苦了……