Open a Password Protected excel and save as unprotected

Share this post
FaceBook  Twitter  Mixx.mn     

 To Open a password Protected excel file, use following code:
 
 
1) Create a Excel application object

2) Set Visible property as True

3) Open Workbook and activate

4) Save sheets without any password

5) Close Workbook  and excel

6) Discard all variables

'1) Create a Excel application object'
     Set objExcel=CreateObject("Excel.Application")

'2) Set Visible property as True     
     objExcel.Visible=True
     fileName ="C:\......\abc.xls"
     excelpwd="pass"
 
   Set oWorkbook=objExcel.Workbooks
'3) Open Workbook and activate
   Set myWkbook=objExcel.Workbooks.open (fileName,0,False,5,excelpwd,excelpwd)
   objExcel.DisplayAlerts=False
   oWorkbook(fileName).Activate

'4) Save sheets without any password'
   For Each wSheet in objExcel.Workbooks
        wSheet.SaveAs fileName,,"",""
   Next
'5) Close Workbook  and excel
   objExcel.Workbooks.Close
   objExcel.Quit
'6) Discard all variables '   
   Set oWorkbook=Nothing
   Set objExcel=Nothing