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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
joefrench

How is the code not working?
 

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
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
 

joefrench

Active Member
Joined
Oct 4, 2006
Messages
357

ADVERTISEMENT

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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
John

Good catch.:)

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

joefrench

Active Member
Joined
Oct 4, 2006
Messages
357
Solved!

That worked perfectly!

Thank you all very much for your help!
 

Forum statistics

Threads
1,141,718
Messages
5,708,072
Members
421,543
Latest member
SGM

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
Top