SuperFly07
August 1st, 2007, 01:29 PM
Do any of you know how to write code in c or vc++ to disable password protected excel files? We want to automate this process. I know how we can disable it manually. We are looking to automate the process for reading excel file with password protections on them. I have a VB script that works fine but can anyone help with similar script to VB but in C or VC++.
Sample VB script code below
this code removes the password
Dim xlApp, xlWb
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open("c:\folder\subfolder\foo.xls", , , , "the_password")
xlWb.Password = ""
xlWb.Save
xlWb.Close
Set xlWb = Nothing
Set xlApp = Nothing
To reapply the password, put this in a *.vbs file:
'this code applies the password
Dim xlApp, xlWb
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open("c:\folder\subfolder\foo.xls")
xlWb.Password = "the_password"
xlWb.Save
xlWb.Close
Set xlWb = Nothing
Set xlApp = Nothing
Sample VB script code below
this code removes the password
Dim xlApp, xlWb
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open("c:\folder\subfolder\foo.xls", , , , "the_password")
xlWb.Password = ""
xlWb.Save
xlWb.Close
Set xlWb = Nothing
Set xlApp = Nothing
To reapply the password, put this in a *.vbs file:
'this code applies the password
Dim xlApp, xlWb
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open("c:\folder\subfolder\foo.xls")
xlWb.Password = "the_password"
xlWb.Save
xlWb.Close
Set xlWb = Nothing
Set xlApp = Nothing