+ Reply to Thread
Results 1 to 10 of 10

One place for your PW

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    One place for your PW

    In a sheet i have several macro's to lock or unlock a sheet/line/cell.

    For example:

    shp.Unprotect Password:="Secret"
    LR = shp.Cells(Rows.Count, 2).End(xlUp).Row
    LC = shp.Cells(5, Columns.Count).End(xlToLeft).Column
    shp.ListObjects("PKB").Resize Range("$B$5", Cells(LR, LC))
    shp.Protect Password:="Secret", UserInterFaceOnly:=True
    Is there a way to place a PW somewhere and to call it. So when i want to change the PW there is one place to change it.

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: One place for your PW

    I am not sure that I understand correctly:


    MyPWD="Secret"
    shp.Unprotect Password:=MyPWD
    LR = shp.Cells(Rows.Count, 2).End(xlUp).Row
    LC = shp.Cells(5, Columns.Count).End(xlToLeft).Column
    shp.ListObjects("PKB").Resize Range("$B$5", Cells(LR, LC))
    shp.Protect Password:=MyPWD, UserInterFaceOnly:=True
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: One place for your PW

    Is there a way to place it somewhere and use it in several macro's?

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: One place for your PW

    Yes...Place it in a cell on a sheet...or store it in a public variable...
    Taking into account that there is no real security in Excel...

    Public PW As String
    Sub Auto_Open()
    PW = "password"
    '! or
    PW = Sheets("Sheet1").Range("X1").Value '! X1 contains Text "password"
    End Sub
    Sub Macro()
    With Sheets("sheet1")
        .Unprotect PW
    End With
    End Sub
    Last edited by sintek; 01-04-2022 at 09:56 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: One place for your PW

    I know there is no security in excel. I use a PW so the people with slim knowledge of excel don't mes thins up.

    So when use the code:
    shP.Unprotect Password:= shY.Cells(1, 1)
    And sheet shY is xlVeryHidden it wil work?

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: One place for your PW

    Yes...I assume all is declared...
    Sub J3v16()
    Dim shY As Worksheet, shP As Worksheet
    Set shY = Sheets("Sheet1")
    Set shP = Sheets("Sheet2")
    shP.Unprotect shY.Cells(1, 1)
    End Sub

  7. #7
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: One place for your PW

    I never use the dim..
    Dim shY As Worksheet, shP As Worksheet
    Why is this necessary?

  8. #8
    Forum Contributor
    Join Date
    01-29-2019
    Location
    Drenthe, Netherlands
    MS-Off Ver
    Dutch Office 2019
    Posts
    291

    Re: One place for your PW

    I don't get it to work.

    I use a userform for typing/asking for a PW with this code.
    Private Sub CommandButton1_Click()
        If TextBox1 <> "" Then
            strPW = TextBox1
            Unload Me
        Else
            MsgBox "U bent vergeten een wachtwoord in te voeren.", vbInformation, ""
            TextBox1.SetFocus
        End If
    End Sub
    For a lot of unlocking i wan't to use a PW placed somewhere central so i can change it easy.

    And unlock a script lock this.

    If shI.Range("P2") = "LOL" Then
        shI.Range("P2") = ""
        Application.ScreenUpdating = False
        strPW = ""
        Wachtwoord_check.Show
        
        If strPW <> "" Then
            If strPW = "Secret" Then
               
            Dim wSheetName As Worksheet
            For Each wSheetName In Worksheets
            wSheetName.Unprotect Password:="Secret"
            wSheetName.Visible = True
            Next wSheetName        
            shI.Activate
            Application.ScreenUpdating = True        
            MsgBox "Alle tabbladen zijn verschenen en ontgredeld.", vbInformation, ""       
            Else
            MsgBox "Het wachtwoord is niet juist.", vbCritical, ""
        End If 
    End If
    Or script like this.

    shp.Unprotect Password:="Secret"
    LR = shp.Cells(Rows.Count, 2).End(xlUp).Row
    LC = shp.Cells(5, Columns.Count).End(xlToLeft).Column
    shp.ListObjects("PKB").Resize Range("$B$5", Cells(LR, LC))
    shp.Protect Password:="Secret", UserInterFaceOnly:=True
    But for one script i want to use another PW.

    Sub Grenswaarden_aanpassen()
    
    Application.ScreenUpdating = False
    
    strPW = ""
    Wachtwoord_check.Show
        
    If strPW <> "" Then
        If strPW = "Onsje meer" Then
            Sheets("Invulblad").Unprotect "Secret"
            Sheets("Invulblad").Range("F:J").Locked = False
            Sheets("Invulblad").Protect Password:="Secret", UserInterFaceOnly:=True
            MsgBox "U kunt de grenswaarden aanpassen.", vbInformation, ""
        Else
                MsgBox "Het wachtwoord is niet juist.", vbCritical, ""
        End If
    End If
    
    Application.ScreenUpdating = True
    
    End Sub
    Is this even possible?

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: One place for your PW

    Mainly because it is important to declare your variables...Makes it easier to find errors...
    See here why Option Explicit declaration for your workbooks is important...

    Did you manually name your sheets in the VBE Project to shY and shP ? from default names Sheet1 etc etc
    Last edited by sintek; 01-04-2022 at 10:44 AM.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: One place for your PW

    Time to upload a sample file so that you can be put out of your misery...
    Explain in detail by referencing requirements...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. count second place and third place of same Value
    By hudson andrew in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-09-2020, 09:28 AM
  2. [SOLVED] Subtraction of 2 decimal place numbers giving 12 decimal place answer
    By njb212 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-22-2018, 09:35 PM
  3. [SOLVED] Place all COLUMNS and place them in 1 Summary sheet SIDE-BY-SIDE
    By countryfan_nt in forum Excel General
    Replies: 1
    Last Post: 04-06-2017, 09:27 AM
  4. [SOLVED] Need result of 1st place and second place
    By Iboughtthefarm.ca in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-13-2016, 09:37 AM
  5. Deciding on 1st place 2nd place etc for a TOP 10 List
    By Brentsa in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-09-2014, 09:54 PM
  6. Replies: 2
    Last Post: 06-24-2007, 10:16 AM
  7. Big sheet..neeed to jump from place to place
    By RHagerty in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-12-2007, 07:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1