title: Protect a VBA project with password
body: <p>My VBA add-in copies some sheets into a new workbook. Although my add-in is project by password the new workbook is not password protected when generated. So the user is able to read the code in it. </p>
  
  <p>I am trying to use protected property to hide the code, but it doesn't seen to work. </p>
  
  <p>Code to generate the new workbook:</p>
  
  <pre><code>Sub CreateNewWorkbook()
  
  On Error GoTo LabelErro
  
  Application.ScreenUpdating = False
  
  Set NewWorkBook = Workbooks.Add
  
  Dim currentSheet As Worksheet
  Dim sheetIndex As Integer
  sheetIndex = 1
  
  With ThisWorkbook
  
      .IsAddin = False
  
      .Sheets("Ajuda").Copy Before:=NewWorkBook.Sheets(sheetIndex)
  
      .Sheets("Fronteira").Copy Before:=NewWorkBook.Sheets(sheetIndex)
  
      .Sheets("Correl").Copy Before:=NewWorkBook.Sheets(sheetIndex)
  
      .Sheets("Atributos").Visible = True
      .Sheets("Atributos").Copy Before:=NewWorkBook.Sheets(sheetIndex)
      .Sheets("Atributos").Visible = xlVeryHidden
  
      .Sheets("Pesos").Copy Before:=NewWorkBook.Sheets(sheetIndex)
  
      .Sheets("Calculos").Copy Before:=NewWorkBook.Sheets(sheetIndex)
  
      .Sheets("Hidden").Visible = True
      .Sheets("Hidden").Copy Before:=NewWorkBook.Sheets(sheetIndex)
      .Sheets("Hidden").Visible = xlVeryHidden
  
      .IsAddin = True
  
  End With
  
  With NewWorkBook
  
      .Sheets("Hidden").Visible = xlVeryHidden
      .Sheets("Calculos").Visible = xlVeryHidden
      .Sheets("Pesos").Range("C1").Formula = "=INDIRECT(""D"" &amp; Hidden!B1+Hidden!B4+1)"
      .Sheets("Pesos").Range("C2").Formula = "=INDIRECT(""E"" &amp; Hidden!B1+Hidden!B4+1)"
      .Protect Password:="teste", Structure:=True, Windows:=True
  
  End With
  
  Exit Sub
  
  LabelErro:
  
          ThisWorkbook.IsAddin = True
  
  End Sub
  </code></pre>