title: VBA "Application-defined or Object-defined error" when protect a worksheet
body: <p>I'm writing a VBA macro that protects another workbook when user clicks a button and open it via current workbook. I got "Application-defined or Object-defined error". I looked into <a href="https://stackoverflow.com/questions/17980854/vba-runtime-error-1004-application-defined-or-object-defined-error-when-select">this post</a> and made sure that the workbook that needs to be opened is unprotected. But the error still occurs. Please help. Thanks!</p>
  
  <pre><code>Sub LockModelParInput()
  Dim wbk As Workbook
  Workbooks.Open (ModelParVarClusLocalPath &amp; "\" &amp; ProN &amp; "_ModelParameter_UserInput.xlsx")
  Set wbk = Workbooks(ProN &amp; "_ModelParameter_UserInput.xlsx")
  wbk.Activate
  With ActiveWorkbook.Worksheets("Model_Rule")
      .Protection.AllowEditRanges.Add Title:="VIF Cut Off Level 2", _
      Range:=Range("C4") *'error occurs on this line*
      .Protection.AllowEditRanges.Add Title:="p_value stay", Range:= _
      Range("D4")
      .Protection.AllowEditRanges.Add Title:="Trend Threshold", Range _
      :=Range("E4")
      .Protection.AllowEditRanges.Add Title:="r_var_ks_penalize", Range _
      :=Range("B10")
      .Protection.AllowEditRanges.Add Title:="fast backward", Range:= _
      Range("C16")
      .Protection.AllowEditRanges.Add Title:="locked forward", Range:= _
      Range("C17")
      .Protection.AllowEditRanges.Add Title:="enhanced stepwise", Range _
      :=Range("C18")
      .Protection.AllowEditRanges.Add Title:="traditional backward", _
      Range:=Range("C19")
      .Protection.AllowEditRanges.Add Title:="sas stepwise", Range:= _
      Range("C21")
      .Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
  End With
  End Sub
  </code></pre>