+ Reply to Thread
Results 1 to 7 of 7

Include a password in VB code.

  1. #1
    GA
    Guest

    Include a password in VB code.

    Can anyone help please.

    I have a workbook that records overtime and the code behind a button on
    the sheet is used to start a new 28 day period. It unprotects the sheet,
    stores the carried forward amount, clears all the entries, enters new
    dates and pastes in the stored carry forward amount and finally
    re-protects the sheet. It all works fine except that many of our users
    make a habit of unprotecting the sheet and entering values over the top of
    functions and then complain next month that the workbook is broken!

    I want to password protect the sheet but that breaks my code.

    Is there a way to include a password in the VB code?

    TIA - GA


  2. #2
    Maurice
    Guest

    RE: Include a password in VB code.

    > Is there a way to include a password in the VB code?

    Yes, there is. I've recently done something similar myself.

    First, I defined a global variable in this way:

    gv_Pwd = "XXX"

    where the XXX is the password with which the sheet is protected. After that,
    you can unprotect and protect the sheet using commands like this:

    ActiveSheet.Unprotect (gv_Pwd)
    ActiveSheet.Protect (gv_Pwd)

    Keep in mind to also protect the VB code (select the the project in the
    menu, right-click it and go to "VBAProject Properties". Under the protection
    tab, you can lock the code from viewing by unauthorized people. Otherwise
    people could snatch the password for the worksheet from the VB code itself .

  3. #3
    flummi
    Guest

    Re: Include a password in VB code.

    Sure:

    Worksheets("xyz").Unprotect (PW)
    Worksheets("xyz").Protect (PW)

    Or

    Activesheet.Unprotect (PW)
    ActiveSheet.Protect (PW)

    Or from the main menu:

    Tools-->Protection-->Protect sheet

    Hans


  4. #4
    George Avery
    Guest

    Re: Include a password in VB code.

    flummi wrote:

    > Sure:


    > Worksheets("xyz").Unprotect (PW)
    > Worksheets("xyz").Protect (PW)


    > Or


    > Activesheet.Unprotect (PW)
    > ActiveSheet.Protect (PW)


    > Or from the main menu:


    > Tools-->Protection-->Protect sheet


    > Hans


    Vielen Dank Hans,

    Why is it that you always find the answer just after you've posted rather
    than just before 8^)

    Just to add to your post - I found that I had to use double quotes in the
    password e.g.
    Worksheet.Unprotect ("PW")

    GA




  5. #5
    flummi
    Guest

    Re: Include a password in VB code.

    <Vielen Dank Hans,
    <
    <Why is it that you always find the answer just after you've posted
    rather
    <than just before 8^)
    <
    <
    <Just to add to your post - I found that I had to use double quotes in
    the
    <password e.g.
    <Worksheet.Unprotect ("PW")
    <

    Hi GA,

    I'm not sure that I quite understand what you mean by "Why is it that
    ....."

    Did I find an answer AFTER I posted?

    Or are you referring to something else?

    Thanks for the clarification. It may be that I did not need quotes
    because I used a numeric password.

    Hans

    Ps: How come you speak German? :-)


  6. #6
    GA
    Guest

    Re: Include a password in VB code.

    On 22 Mar 2006 05:38:29 -0800, "flummi" <[email protected]> wrote:

    [snip]
    >I'm not sure that I quite understand what you mean by "Why is it that
    >...."
    >
    >Did I find an answer AFTER I posted?
    >
    >Or are you referring to something else?
    >
    >Thanks for the clarification. It may be that I did not need quotes
    >because I used a numeric password.
    >
    >Hans
    >
    >Ps: How come you speak German? :-)



    I was talking about myself there Hans - just after I posted, I found
    the answer myself - almost as soon as I'd clicked submit. I meant why
    do I always find the answer just after I have actually posted rather
    than just before.

    Ps: Meine Mutter war Deutsch :^)
    Thanks again,
    GA

  7. #7
    flummi
    Guest

    Re: Include a password in VB code.

    Funny, how ambiguous language can be. :-)

    You are most welcome, George.

    Und viele Gruesse aus dem kalten Deutschland!

    Hans


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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