Hi,
I have one excel template with lots of macros. I am protecting the workbook while opening and before close unprotecting this for further processing by a component.
Workbook protection is working on workbook_open event but it is not unprotecting the workbook on close.
Why i am saying this because when i checked the log of the component which populates the sheets of this workbook, it is throwing following error:
The VB Application identified by the event source logged this Application ProcessExcelFile: Thread ID: 712 ,Logged: Error: -2147467259-Could not decrypt file.
Following code snippet is written under as macro.
Any idea/suggestion would be of great help.Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = False
Application.StatusBar = "Unprotecting the Excel workbook."
If ActiveWorkbook.ProtectStructure = False And ActiveWorkbook.ProtectWindows = False Then
ActiveWorkbook.Unprotect Password:="****" ', Structure:=True, Windows:=True
End If
ActiveWorkbook.Save
Application.EnableEvents = True
On Error GoTo 0
End Sub
Thanks in advance.
![]()
Bookmarks