ADDING A PASSWORD AT THE BEGINNING OF CODE. No straight answer on forum.

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
I have looked at several post and have not been able to find a concrete answer for this problem. There needs to be a masked password to be entered at the beginning of some code before if can continue to run. I have found and am currently using
PHP:
If UCase(InputBox("Enter Password")) <> "1288" Then Exit Sub
With ActiveSheet
.Unprotect Password:="1288"
all the research I have done on this says this code cannot be modified to be masked, that there has to be a userform made and the password properties needs to have a * in it. The information runs out at that there is nothing showing how to apply that in the code to have the userform popup and then what to do.... Any Help with this would be appreciated. Thanks
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I have looked at several post and have not been able to find a concrete answer for this problem. There needs to be a masked password to be entered at the beginning of some code before if can continue to run. I have found and am currently using
PHP:
If UCase(InputBox("Enter Password")) <> "1288" Then Exit Sub
With ActiveSheet
.Unprotect Password:="1288"
all the research I have done on this says this code cannot be modified to be masked, that there has to be a userform made and the password properties needs to have a * in it. The information runs out at that there is nothing showing how to apply that in the code to have the userform popup and then what to do.... Any Help with this would be appreciated. Thanks


You will have to use a userform with a textbox, and set the passwordchar of this field to "*" instead of a application.inputbox

you can find a workbook with a userform and a password field. here
http://db.tt/wgHUYrrB
 
Last edited:
Upvote 0
ok, After making the userform how do I edit the code I have to make this work?? I am currently using one that does not mask the password.

Sub FINALIZED_BY_QC()

Dim newFileName As String
Dim appendtext As String

If UCase(InputBox("Enter Password")) <> "1288" Then Exit Sub
With ActiveSheet
.Unprotect Password:="1288"
With .Range("J24").Interior
.Pattern = xlSolid
.PatternColorIndex = 1
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
appendtext = "-FINAL"
.Range("J24").FormulaR1C1 = appendtext
' ActiveSheet.Unprotect
Cells.Select
Selection.Locked = True
Range("W4:W23").Select
Selection.Locked = False
Selection.FormulaHidden = False

Range("W3").Select
ActiveCell.FormulaR1C1 = "Assistant Purchasing/" & Chr(10) & "Dept. Comments"
Range("W3").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False

End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
Range("W3:W23").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone

With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
End With

With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("W3").Select
ActiveWorkbook.Save
'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

ActiveSheet.Buttons.Add(1081.10769230769, 32.1230769230769, 192.184615384615, _
53.7230769230769).Select

Selection.OnAction = "PURCH_COMMENTS"
Selection.Characters.Text = "SAVE COMMENTS"
With Selection.Characters(Start:=1, Length:=13).Font
.Name = "Calibri"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With



'.UsedRange.Locked = True
.Protect Password:="1288", DrawingObjects:=True, Contents:=True, Scenarios:=True
End With
With ActiveWorkbook
oldFileName = .FullName
newFileName = Left(.FullName, InStrRev(.FullName, ".xls") - 1) _
& appendtext
.SaveAs Filename:=newFileName
End With
Kill oldFileName

End Sub
 
Upvote 0
Arul, I dont need the user form to popup right when the workbook does. I need it to work when I select a key combination(ctrl+alt+b) to run the macro
 
Upvote 0
Close the userform when it pops up goto the module "ThisWorkbook" and copy the code to a regular module, change the sub name to anything you want and assign a shortcut key
 
Upvote 0
Arul, Ive made the userform. I have it were it comes up when I hitthe key combination. When I enter the password it does nothing.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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