问题与表保护

我正在构build一个工具,用户可以为其各自的项目创build工作表,稍后将用于自动生成幻灯片。 一切都很好,直到我试图添加表保护,以限制他们的编辑只有input单元格所需…

这是模板表格,每当他们添加一个新的项目时,它们都会被复制一个新的名字

在这里输入图像说明

正如你所看到的工作表是受保护的,但我可以编辑我需要的单元格(例如D2),因为它们没有被locking

在这里输入图像说明

通过表单收集一些用户input后,我使用此代码将模板表复制到同一工作簿中的新工作表… wsShortBlank是模板工作表

wsShortBlank.Visible = xlSheetVisible With ThisWorkbook wsShortBlank.Copy After:=.Sheets(.Sheets.Count) Set sh = ActiveSheet 'the copied sheet should be the active one, so grab a handle to it End With wsShortBlank.Visible = xlSheetVeryHidden sh.Name = txtPE.Value & " " & txtPEC.Value Unload Me With sh .Activate .Unprotect password:=myPassword 'add done editing button .Buttons.Add(468.75, 30, 210.75, 60.75).Select Selection.OnAction = "doneEditing" Selection.Characters.Text = "Done Editing" 'populate the data we know .Range("B33").Value = comboClass.Value .Range("B34").Value = txtPE.Value .Range("B35").Value = txtPEC.Value .Range("B36").Value = txtTask.Value .Protect password:=myPassword .Range("D2").Select 'stick the cursor in the first input field End With Application.ScreenUpdating = True 

我现在有这张表

在这里输入图像说明

“完成编辑”button链接到隐藏当前工作表的子工具,并重新显示主菜单表单

但是,如果我试图编辑单元格D2,我得到这个

在这里输入图像说明

就好像该单元格被locking一样。 但是,如果我点击另一张纸,然后点击返回到这张纸,我可以编辑单元格D2就好了。

是什么赋予了?

作为一个更新,我还修改了代码,以便在复制它所经过的工作表之后,单独设置单元格的locking属性。因此,这些代码块被添加到上述代码块的末尾

  .Range("D2:D7").Locked = False .Range("D11:D12").Locked = False .Range("C17:J19").Locked = False .Range("C23:G23").Locked = False .Range("D24:H24").Locked = False .Range("E25:I25").Locked = False .Range("F26:J26").Locked = False .Range("B30:G30").Locked = False .Protect password:=myPassword 

但是没有什么区别。