+ Reply to Thread
Results 1 to 6 of 6

Putting passwords in VBA code

  1. #1
    Forum Contributor
    Join Date
    03-10-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    180

    Putting passwords in VBA code

    Hi,

    I am trying to understand the best way to deal with passwords in VBA. I have a spreadsheet with multiple sheets that each have the same password. When I run various macros on each sheet it takes off the password and then puts it back on. Currently, however, the password is hard coded into the macro so each time I literally write the password. If the password were to then change for some reason it would mean having to replace all instances of the password throughout the code.

    I believe you can declare the password as a global of some kind (if that it the right terminology - apologies I am still very new to VBA) so that you only have to change it in one place.

    1. How do you set a password as a "global" for all macros in a project
    2. What code do you then use in each macro to refer to this global?

    Thanks
    MissDB

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Putting passwords in VBA code

    Regardless, where you put in the password, be it as a global or local, if the VBA project is not password protected, the person can access the code and change the passwords. You can protect the codes with a VBA password and attach the codes to a button, so that the person who wants to use the code can access them by pressing the buttons.

    Microsoft office products are not known for good security. Any person with a bit of knowledge can by pass them. I know, I will get in trouble with the site rules, but there are lots of codes which can easily crack a VBA password. Just google it and see what I mean.

  3. #3
    Forum Contributor
    Join Date
    03-10-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Putting passwords in VBA code

    Hi,

    Yes I know about being able ot change passwords, I am not paritculart worried about that, I don't work in an environment where that is really an issue. The only reason the sheets are password protected is to prevent people accidentally type over things etc.

    My query is more about how to put a password in as a global and then how to refer to it in the code so that we don't have to change it in multiple places should it need to change (not how to make it fail safe)

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Putting passwords in VBA code

    You could just add something like this at the top of a standard module.
    Please Login or Register  to view this content.
    You'll then be able to refer to the constant in any other module like this for example.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Putting passwords in VBA code

    Okay!
    Norie has provide you a solution.
    "prevent people accidentally type over things etc."
    This sound more of protecting the range or sheet using a normal excel password.

  6. #6
    Forum Contributor
    Join Date
    03-10-2014
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Putting passwords in VBA code

    Thank you! :-)

+ 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. Excel vba code for multi user logins and passwords
    By Willow350 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2016, 10:26 PM
  2. putting a function into VB code
    By Pontiac in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-05-2015, 10:18 PM
  3. Run VBA code based on multiple passwords.
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2015, 11:32 AM
  4. Putting Code To A Button In Excel / VB
    By Rapid in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-16-2013, 12:04 PM
  5. Replies: 10
    Last Post: 12-16-2011, 12:41 PM
  6. Excel 2007 error with code for creating passwords
    By CMSS in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-04-2010, 11:52 AM
  7. Putting Input box into existing code
    By jpthelpguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2009, 02:14 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