ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Cancel the Protect of Excel with VB and save it with a new password again (https://www.excelbanter.com/excel-programming/414972-how-cancel-protect-excel-vbulletin-save-new-password-again.html)

NTorch

How to Cancel the Protect of Excel with VB and save it with a new password again
 
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




Dave Peterson

How to Cancel the Protect of Excel with VB and save it with a newpassword again
 
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).




NTorch wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 10:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com