gAsBo WinTag = .ProtectStructureOr.ProtectWindowsEndWithShTag =FalseForEachw1InWorksheets ShTag = ShTagOrw1.ProtectContentsNextw1IfNotShTagAndNotWinTagThenMsgBox MSGNOPWORDS1, vbInformation, HEADERExitSubEndIfMsgBox MSGTAKETIME, vbInformation, HEADERIfNotWinTagThenMsgBox MSGNOPWORDS2, vbInformation, HEA...
ActiveSheet.Protect Password:=641112 ' 保护工作表并设置密码 ActiveSheet.Unprotect Password:=641112 '撤消工作表保护并取消密码 '本示例关闭除正在运行本示例的工作簿以外的其他所有工作簿,并保存其更改内容 。 For Each w In Workbooks If w.Name ThisWorkbook.Name Then w.Close SaveChanges:=True End If Next ...
ws.Protect Password:=ps Next ws End Sub 如果您想一次性保护所有工作表,这里有一个适合您的代码。运行此宏时,您将获得一个用于输入密码的输入框。输入密码后,单击“确定”。并确保注意CAPS。If you want to protect your all worksheets in one go here is a code for you. When you run this macro,...
To prevent your source code from prying eyes you can use password protection of the VBA Editor (VBE) and VBA Project in your MS Excel workbook. It is a standard technique to protect your macros in all MS Office applications which is available by default. You can protect VBA Project and VB...
ws.Protect Password:=ps Next ws End Sub 'Translate By Tmtony 如果您想一次性保护所有工作表,这里有一个适合您的代码。运行此宏时,您将获得一个用于输入密码的输入框。输入密码后,单击“确定”。并确保注意CAPS。 38. 调整工作表中所有图表的大小 ...
ws.Protect UserInterfaceOnly:=True ws.Range("A1").Value = "当前用户:" & currUser & "(" & arrUser(i, 2) & ") " & Chr(10) & "用户权限:" & currPermission If currPermission = "All" Or InStr(currPermission, "/用户权限表/") Then ...
", vbCritical Me.txtPassWord.SetFocus Exit Sub End If strName = "产品.xlsx" '使用文件对话框取得另存为的文件名 With Application.FileDialog(2) 'msoFileDialogSaveAs .InitialFileName = strName If .Show Then strName = .SelectedItems(1) If Not strName Like "*....
'保护工作表,密码123,仅在用户界面有效,用代码可以操作工作表 ws.Protect Password:=123, userinterfaceonly:=True 20、Sort:工作表排序 With ws.Sort .SortFields.Clear .SortFields.Add Key:=Range("b2:b10"), _ SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal .SetRan...
下面的代码保护工作表,同时允许在其中使用筛选和VBA宏。Private Sub Workbook_Open() With Worksheets("Sheet1") .EnableAutoFilter = True .Protect Password:="123", Contents:=True, _ UserInterfaceOnly:=True End WithEnd Sub注意,这段代码放置在ThisWorkbook代码模块中,因此...
Private Sub CheckBox1_Click() If CheckBox1.Value = True Then ActiveSheet.Protect Password:="YourPassword" Else ActiveSheet.Unprotect Password:="YourPassword" End If End Sub 请注意,上述代码中的"YourPassword"应替换为您要使用的实际密码。 关闭VBE并返回Excel工作表。 现在,当您在复选框上单击时,它将...