Hi
I am using VBA to copy over a range of workbooks to a new location. I want to clear the data from the worksheets which are password protected. I do know the password. Everything works okay until I insert ActiveSheet.Unprotect Password:="Test" then I get a subscript out of range message. Does anyone know how to get around this?
Code:
Sub test()
Workbooks.Open Filename:="c:\Try this.xlsm", Password:="one", WriteResPassword:="two"
ChDir "c:\New\"
ActiveWorkbook.SaveAs Filename:= _
"C:\New\Try this 1.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveSheet.Unprotect Password:="Test"
End Sub