ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unprotect Sheet Password in Macros (https://www.excelbanter.com/excel-programming/343267-unprotect-sheet-password-macros.html)

Theresa

Unprotect Sheet Password in Macros
 
Hi:

I have an Excel file that has been used as a template to create 800+ files
that has the protection worksheet applied. I now what to add more formulas
to this file and want to use a macro to do it. How can I enter the unprotect
password automaticcaly as part of the macro and then protect the sheet again
before saving and closing?

Thanks

Jim Thomlinson[_4_]

Unprotect Sheet Password in Macros
 
public const MYPASSWORD as string = "supersecret" 'At the top of a module

Sub Stuff()
sheets("Sheet1").unprotect MYPASSWORD
'Do your stuff
sheets("Sheet1").protect MYPASSWORD
End Sub
--
HTH...

Jim Thomlinson


"Theresa" wrote:

Hi:

I have an Excel file that has been used as a template to create 800+ files
that has the protection worksheet applied. I now what to add more formulas
to this file and want to use a macro to do it. How can I enter the unprotect
password automaticcaly as part of the macro and then protect the sheet again
before saving and closing?

Thanks


sebastienm

Unprotect Sheet Password in Macros
 
To unprotect a worksheet, assuming the book is already open:
Dim Wsh as worksheet
set wsh= activeworkbook.Worksheets(1) 'Eg: for 1 sheet of active book

wsh.unprotect "your_password"
'... do what you have to do here
'then reprotect with wsh.protect .....

(If you meant to unprotect a protected vba project, not the sheet, then it
is not possible through code)

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Theresa" wrote:

Hi:

I have an Excel file that has been used as a template to create 800+ files
that has the protection worksheet applied. I now what to add more formulas
to this file and want to use a macro to do it. How can I enter the unprotect
password automaticcaly as part of the macro and then protect the sheet again
before saving and closing?

Thanks


Tom Ogilvy

Unprotect Sheet Password in Macros
 
Activesheet.Unprotect Password:="ABC"


ActiveSheet.Protect Password:="ABC"
ActiveWorkbook.Close Savechanges:=True

--
Regards,
Tom Ogilvy

"Theresa" wrote in message
...
Hi:

I have an Excel file that has been used as a template to create 800+ files
that has the protection worksheet applied. I now what to add more

formulas
to this file and want to use a macro to do it. How can I enter the

unprotect
password automaticcaly as part of the macro and then protect the sheet

again
before saving and closing?

Thanks




zuhair

Unprotect Sheet Password in Macros
 
Sir,
I have a web site showing stock prices. By marking the rows and linking to
excel comand, sheet1 is linked and the data changing in the web is reflected
in sheet1. the problem is that in Worksheet_Change sub is not getting
activated although if I key in a number tha event is happening. any help.

code bellow

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

k = 1
Application.EnableEvents = False
SheetName = Worksheets("Sheet1").Cells(Target.Row, 2)

Do While Worksheets("Sheet1").Cells(Target.Row, k) < ""
Worksheets(SheetName).Cells(SheetsLastRow(Target.R ow), k) =
Worksheets("Sheet1").Cells(Target.Row, k)
k = k + 1
Loop

Worksheets(SheetName).Cells(SheetsLastRow(Target.R ow), k) = Time

If Target.Column = 3 Then
Call CheckThePrice(Target.Row)

End If

SheetsLastRow(Target.Row) = SheetsLastRow(Target.Row) + 1

Application.EnableEvents = True

End Sub


this code does what is suppose to do if manualy we chang the cell value then
hit enter. but not when the value is changed by link to the web site.

please email me.

thank you.


"sebastienm" wrote:

To unprotect a worksheet, assuming the book is already open:
Dim Wsh as worksheet
set wsh= activeworkbook.Worksheets(1) 'Eg: for 1 sheet of active book

wsh.unprotect "your_password"
'... do what you have to do here
'then reprotect with wsh.protect .....

(If you meant to unprotect a protected vba project, not the sheet, then it
is not possible through code)

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Theresa" wrote:

Hi:

I have an Excel file that has been used as a template to create 800+ files
that has the protection worksheet applied. I now what to add more formulas
to this file and want to use a macro to do it. How can I enter the unprotect
password automaticcaly as part of the macro and then protect the sheet again
before saving and closing?

Thanks



All times are GMT +1. The time now is 05:08 PM.

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