Pulling password from a hidden cell inside a running macro

joefrench

Active Member
Joined
Oct 4, 2006
Messages
357
I have many sheets that run macros which need the password protection to be lifted while running certain portions of the macros. Does anyone know of a way to pull the password from a cell on a hidden sheet? I have tried the following:

Code:
Dim pw As String
Set pw = Sheet3.Range("a3")
ActiveSheet.Unprotect Password:=pw

ActiveSheet.Publish_Button.Visible = False
ActiveSheet.Print_Button.Visible = False

Auto_republish

ActiveSheet.Publish_Button.Visible = True
ActiveSheet.Print_Button.Visible = True

ActiveSheet.Protect Password:=pw, userinterfaceonly:=True
send_msg

And:

Code:
ActiveSheet.Unprotect Password:=Sheet3.Range("a3").Value

ActiveSheet.Publish_button.Visible = False
ActiveSheet.Print_Button.Visible = False

AutoRepublish

ActiveSheet.Publish_button.Visible = True
ActiveSheet.Print_Button.Visible = True

ActiveSheet.Protect Password:=Sheet3.Range("a3").Value, _
userinterfaceonly:=True

send_msg

Neither of which worked.

You're help is greatly appreciated!

EDIT: Changed to Code Tags - Smitty
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
There are diffrent codings, depending on if the data cell is in a Hidden Range or if the Sheet is hidden?

Sub myRowHome()
Dim myR&

myR = ActiveCell.Row

If ActiveSheet.Cells(myR, 1).EntireColumn.Hidden = False Then
ActiveSheet.Cells(myR, 1).Select
Else
ActiveSheet.Cells(myR, 1).EntireColumn.Hidden = False
ActiveSheet.Cells(myR, 1).Select
End If
End Sub


If it is the whole sheet then:


Sheets("Sheet2").Visible = True

'Your Code Here!

Sheets("Sheet2").Visible = False
 
Upvote 0
joefrench

How is the code not working?
 
Upvote 0
This much worked for me:
Code:
Sub NewTest()
Dim pw As Range
Set pw = Sheet3.Range("a3")
    MsgBox pw
    ActiveSheet.Unprotect Password:=pw
End Sub

Note: changed pw from String to Range
 
Upvote 0
It is giving me the following:

Run time error '1004':
The password you supplied is not correct. Verify that the CAPS LOCK
key is off and be sure to use the correct capitalization.
 
Upvote 0
John

Good catch.:)

Didn't see that, thought the user was saying the problem was with the sheet being hidden.
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,317
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top