运行macros到一个受保护的工作表 – 没有其他答案

开始…

我已经创build了一个由1个工作簿中的31个工作表组成的项目表格。 被称为“NOV概要”的工作表1是摘要页面。 其他30张工作表都有各种各样的细节。

我创build的macros与30个工作表上的选项button相关,当select在“NOV Summary”页面上放置信息时。

这个总结页面基本上是在用户在其他工作表上input信息时自动创build和填写的。 因此,我想保护“NOV Summary”页面,但仍然有marcos运行。

我的vba知识基本上是最基本的,在所有search之后我都无法解决。

这是我正在使用的马科斯的一个例子—

子指定符()

''说明符macros''

Sheets("NOV Summary").Select Range("D4").Select ActiveCell.FormulaR1C1 = "Specifier" With ActiveCell.Characters(Start:=1, Length:=9).Font .Name = "Calibri" .FontStyle = "Regular" .Size = 11 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ThemeColor = xlThemeColorLight1 .TintAndShade = 0 .ThemeFont = xlThemeFontMinor End With Range("D4").Select Sheets("PR1311001").Select 

结束小组

如果你可以帮助把正确的代码,让这种情况发生,将不胜感激!

Mnay谢谢

汤姆

您可以在运行macros之前取消保护表格,然后再保护它

 Public Sub PasswordTest() Dim password As String Dim ws As Worksheet Set ws = Sheet1 password = "password123" 'Check if sheet is protected If ws.ProtectContents Then ws.Unprotect password End If '******* 'put your code here '******* 'Protect sheet again ws.Protect password Exit Sub 'error handling block err: MsgBox err.Description, "an error occured" 'if the sheet isn't protected then we should protect it again. If ws.ProtectContents = False Then ws.Protect password End If End Sub 

正如注释中指出的那样,您可以在保护工作表时设置UserInterFaceOnly参数。 这将保护它,但允许macros继续工作。

 ws.Protect Password:=password, UserInterFaceOnly:=True 

你可以在这里读到它..

http://www.ozgrid.com/VBA/excel-macro-protected-sheet.htm