Consulting

Results 1 to 11 of 11

Thread: Userform to change password in VBE

  1. #1
    VBAX Contributor CaptRon's Avatar
    Joined
    Mar 2007
    Location
    Austin, Texas
    Posts
    141
    Location

    Userform to change password in VBE

    I've created a workbook that allows the user to access the data entry sections by entering a password into a userform. Those without that permission are confined to view data only. I've used the same simple password throughout the workbook, not different passwords in each of the macros where needed.

    I'd like to be able to devise a method that would permit the office manager to readily change that single password in all the code without having to go into the VBE and locate each instance of it. I don't even want them in the VBE at all, if possible. Don't change the oil, just drive, if you get my meaning.

    I wonder if it is possible to make a change like this with a userform. Any ideas?

    Thanks.

    Ron

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Are you working in a Server setup? My initial thought is to store user names and passwords in a text file and read in the password from that file. If you want to keep it on each PC, look at SaveSettings/GetSettings, where you can store data in the registry. Check the KB for an item on this.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Depends how secure you need it to be (relatively speaking, given how inherently insecure Excel passwords are). You could store the password in a hidden workbook name and use that in your code. At the very least, you should not be hardcoding the password in multiple locations in the code - declare a constant and refer to that in your code; then you only have to change the password in one location.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't think this meets Ron's criteria of ... I'd like to be able to devise a method that would permit the office manager to readily change that single password in all the code without having to go into the VBE and locate each instance.

    It looks that he wants the password away from Excle/VBA, in a simple to change place. MD seemed to answer that perfectly.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You could store the password in a hidden workbook name and use that in your code
    Seems on point to me. The rest was merely addressing my inference that the password was hardcoded in multiple places.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    VBAX Contributor CaptRon's Avatar
    Joined
    Mar 2007
    Location
    Austin, Texas
    Posts
    141
    Location
    Rory,

    I do need to declare that password once. I should have thought of that. I do that with values in formulas. I suppose I would place that in This Workbook. It has been easy enough for me to do using the replace function on the toolbar applied to the whole project ("oldpswrd" replaced with "newpswrd"). Could you suggest some code that would properly declare that password?

    Anyway, that's half the solution. Being able to change that password is the other half. The file will reside on a P drive on our server so everyone in the office can access it but we only want assigned individuals to have the ability to manipulate the data. The office manager may wish to alter the password from time to time and I may be fishing.

    MD, please tell me more about the method you suggested and where I might go for more info to learn about it. I don't expect to be spoon fed everything here. I appreciate the help and direction from all.

    Ron
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes.

  7. #7
    I'd go with MD's suggestion but I'd make sure the store password was encoded, you take the submitted text, encode that and if it matches the stored version, allow the code to run.
    Obviously you need to use one way encryption otherwise they will just reverse engineer it.
    2+2=9 ... (My Arithmetic Is Mental)

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    File permissions should be sufficient.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This users the txt file method and the UserName/Password in the file.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Contributor CaptRon's Avatar
    Joined
    Mar 2007
    Location
    Austin, Texas
    Posts
    141
    Location
    Hello MD,

    I tried your TestProtect. Is the .txt supposed to update when you enter something in the new password userform? Or do I go into the txt file and enter the info there?

    Ron
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes.

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The userform will update the text file, or you can edit it directly.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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