+ Reply to Thread
Results 1 to 6 of 6

Global Constant Password ThisWorkbook Module

  1. #1
    Registered User
    Join Date
    08-13-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Global Constant Password ThisWorkbook Module

    Hi all,
    I'm a relative VBA newbie.
    My problem is as follows:
    I have deined in a standard module a public constant that serves as a password, I.e. i have
    Public const PASSWORD = "abc123", for example.

    Now, on protecting/unproecting a sheet from the ThisWorkbook module, I am unable to use this PASSWORD global constant.
    I.e., the following fails

    Sheets("Sheet1").Unprotect PASSWORD:=PASSWORD

    I am certain that Sheet1 is protected by "abc123". If i replace the above with:

    Sheets("Sheet1").Unprotect PASSWORD:="abc123"

    everything works fine.

    Hope that's clear, let me know if not. Thanks for any help anyone can offer.

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Global Constant Password ThisWorkbook Module

    Hi,

    You use one of the reserved keywords : PASSWORD
    Change this to something else, like PASS, PASSWORD1, etc

    Regards
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Global Constant Password ThisWorkbook Module

    Below code works without any problems in my system.
    Please Login or Register  to view this content.
    Are you sure the PASSWORD declaration is exactly what you typed or some space or any other hidden character is still there..?
    ________________________________________________________
    If your problem is solved, update the thread as SOLVED: Go to the top of the first post-Select Thread Tools-Select Mark thread as Solved OR - Go to the first post - Click edit- Click Advance- Just below the word "Title:" you will see a dropdown with the word No prefix.- Change to Solve- Click Save.

    Show your gratitude to the person who helped you solving your problem by clicking on star button at the bottom of such post.

  4. #4
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Global Constant Password ThisWorkbook Module

    And also use any other string for costant. Pwd or Passwrd

  5. #5
    Registered User
    Join Date
    08-13-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Global Constant Password ThisWorkbook Module

    I am positive that everything is typed in correctly. Appreciate all your rapid responses.
    I will try defining the a new Global Constant PASSWORD2="abc123" and use PASSWORD2 in my ThisWorkbook module.
    Thanks

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Global Constant Password ThisWorkbook Module

    Quote Originally Posted by haripopuri View Post
    Below code works without any problems in my system.
    Please Login or Register  to view this content.
    Are you sure the PASSWORD declaration is exactly what you typed or some space or any other hidden character is still there..?
    Because you run it from the same module, try to run it from workbook like this :

    Please Login or Register  to view this content.
    Quote Originally Posted by Delvesy888 View Post
    I am positive that everything is typed in correctly. Appreciate all your rapid responses.
    I will try defining the a new Global Constant PASSWORD2="abc123" and use PASSWORD2 in my ThisWorkbook module.
    Thanks
    You are welcome, and don't forget to mark this thread as SOLVED.

+ 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. How do I make ThisWorkbook.Name a global variable?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-22-2011, 11:35 AM
  2. Replies: 1
    Last Post: 08-30-2011, 02:23 AM
  3. Accessing Global Variables defined in ThisWorkbook Module
    By smz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2010, 08:26 PM
  4. Code in 'ThisWorkbook' module in add-in?
    By karan in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-04-2009, 03:36 AM
  5. [SOLVED] Calls from sheet module to ThisWorkbook module
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2005, 11:05 AM

Tags for this Thread

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