How to Cancel the Protect of Excel with VB and save it with a new password again

N

NTorch

I need to Open an Excel file with protection password and save it with a new
password again after changing the Excel.

Now I know only:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet


Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open("D:\aa.xls", , , , 123)

x1Book.Unprotect ("123")
Set xlsheet = xlBook.Worksheets(1)
xlsheet.Cells(1, 1) = abc

xlBook.Close (True)
xlApp.Quit

But x1Book.Unprotect ("123") is error.
And I don't know how to cancel the protect of Excel with VB ;and I don't
know how to save it with a new password again after changing the Excel.


Any help would be most appreciated.

Torch Nee
 
D

Dave Peterson

Are you running this from excel's VBA?

You can change the password to open by saving it with a new password. You can
look at VBA's help for .saveas to see the parms.

Or you could use:

xlbook.password = "newpassword"
xlbook.save
xlbook.close false

or replace the last two lines with
xlbook.close true

And (in general) watch your typing. You have xLapp (with an ELL) and x1App
(with a one).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top