我给VBA下的定义:VBA是个人小型自动化处理的有效工具。可以大大提高自己的劳动效率,而且可以提高数据的准确性。我这里专注VBA,将我多年的经验汇集在VBA系列九套教程中。
【分享成果,随喜正能量】人与人,人与事之间,皆有缘相由心生,境随心转,你把对方当成是菩萨,他就是菩萨,你把对方当作是魔鬼,他就是魔鬼 。
第四章 工作表代码Worksheet Codes
6 保护工作表Protect WorksheetSub nzProtectWS() '保护工作表
ActiveSheet.Protect "123", True, True
End Sub
如果要保护工作表,可以使用此宏代码。您所要做的就是在代码中提及您的密码。
If you want to protect your worksheet you can use this macro code. All you have to do just mention your password in the code.
本节内容参考程序文件:Chapter04.xlsm7 取消保护工作表Un-Protect WorksheetSub nzUnprotectWS() '取消保护工作表
ActiveSheet.Unprotect "123"
End Sub
如果要取消对工作表的保护,可以使用此宏代码。您所要做的就是提及您在保护工作表时使用的密码。
If you want to unprotect your worksheet you can use this macro code. All you have to do just mention your password which you have used while protecting your worksheet.
本节内容参考程序文件:Chapter04.xlsm8 对工作表进行排序Sort WorksheetsSub nzSortWorksheets() '对工作表进行排序
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult
iAnswer = MsgBox("是否按按升序排序工作表?" & Chr(10) _
& "单击NO将按降序排序", vbYesNoCancel + vbQuestion + vbDefaultButton1, "排序工作表")
For i = 1 To Sheets.Count
For j = 1 To Sheets.Count - 1
If iAnswer = vbYes Then
If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
Else
If iAnswer = vbNo Then
If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then Sheets(j).Move After:=Sheets(j + 1)
End If
End If
Next j
Next i
End Sub
此代码将帮助您根据工作表的名称对工作簿中的工作表进行排序。
This code will help you to sort worksheets in your workbook according to their name.
本节内容参考程序文件:Chapter04.xlsm我20多年的VBA实践经验,全部浓缩在下面的各个教程中: