I am getting an automation error when I try to protect a VBProject and email the workbook as attachment. What am I missing here?
Here is code to Protect VB project:
Sub ProtectVBProject(WB As Workbook, ByVal strPassWord As String)
Dim vbProj As Object
Set vbProj = WB.VBProject
'Is it already locked!    
If vbProj.Protection = 1 Then Exit Sub
Set Application.VBE.ActiveVBProject = vbProj
'SendKeys to set the project password    
SendKeys "+{TAB}{RIGHT}%V{+}{TAB}" & strPassWord & "{TAB}" & strPassWord & "~"
Application.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
   'Close and Save    
    WB.Close True    
    End Sub
Here is code that calls ProtectVBProject to Protect VB project and attach the workbook and mail it
 TempFilePath = Environ$("temp") & "\"
    TempFileName = "Email Test " & Sourcewb.Name & " " _
                 & Format(Now, "dd-mmm-yy h-mm-ss")
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With Destwb
    .SaveAs TempFilePath & TempFileName & FileExtStr, _
            FileFormat:=FileFormatNum
    On Error Resume Next
    With OutMail
        .To = "aab2323@example.com"
        .CC = ""
        .BCC = ""
        .Subject = "Test Subject"               
        Call ProtectVBProject.ProtectVBProject(Destwb, "pa$$w0rd!")                
        .Attachments.Add Destwb.FullName
        .Send
    End With
    On Error GoTo 0
    .Close SaveChanges:=False
    Destwb.Close SaveChanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing