+ Reply to Thread
Results 1 to 3 of 3

Using "Named" Variables

  1. #1
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    1

    Using "Named" Variables

    I've named the password to my protected workbook using this code:

    ActiveWorkbook.Names.Add Name:="password", RefersTo:=pWord1

    I then want to be able to close down Excel, switch off the computer, open all back up again and retrieve the password. I've tried the code:

    pWord1 = Evaluate(ActiveWorkbook.Names("password").RefersTo)

    But I get this:

    Run-time error '1004': Application-defined or object-defined error

    Can anybody help me to retrieve the password from the named variable after closing?

    This is to help me protect and unprotect the workbook whenever I open and close it to timestamp a spreadsheet in it. I don't want the daily user to be able to see the time stamped spreadsheet and so need to keep it hidden and the spreadsheet protected over the course of many days when I'm not round.

    Many thanks,
    Mark

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Using "Named" Variables

    ActiveWorkbook.Names.Add Name:="password", RefersTo:=pWord1
    Your above code nothing going to do with Sheet/Workbook protection.

    Your code is just creating a Workbook level of named range with the name of "password" and it is getting the range from another named range called pWord1.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Using "Named" Variables

    I can't see anything wrong with the code - can you see the name in Name Manager when you reopen the file? (I assume you saved the file after adding the name)
    Remember what the dormouse said
    Feed your head

+ 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 to use named ranges in VBA code using "Columns" and a variation on "Range"
    By haljam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2014, 02:48 PM
  2. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  3. Strings Variables in Range("A1").Formula = "=index/match" ?
    By nadnerb5 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-19-2012, 05:07 PM
  4. Named Range = "CountryA" OR "CountryB"
    By f0urchette in forum Excel General
    Replies: 0
    Last Post: 03-05-2012, 04:20 AM
  5. Replies: 3
    Last Post: 06-04-2011, 10:56 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