close

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 - GAgt; 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 = quot;XXXquot;

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 quot;VBAProject Propertiesquot;. 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 .

Su

Worksheets(quot;xyzquot;).Unprotect (PW)
Worksheets(quot;xyzquot;).Protect (PW)

Or

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

Or from the main menu:

Tools--gt;Protection--gt;Protect sheet

Hansflummi wrote:

gt; Su

gt; Worksheets(quot;xyzquot;).Unprotect (PW)
gt; Worksheets(quot;xyzquot;).Protect (PW)

gt; Or

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

gt; Or from the main menu:

gt; Tools--gt;Protection--gt;Protect sheet

gt; 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 (quot;PWquot;)

GA

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

Hi GA,

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

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? :-)On 22 Mar 2006 05:38:29 -0800, quot;flummiquot; gt; wrote:

[snip]
gt;I'm not sure that I quite understand what you mean by quot;Why is it that
gt;....quot;
gt;
gt;Did I find an answer AFTER I posted?
gt;
gt;Or are you referring to something else?
gt;
gt;Thanks for the clarification. It may be that I did not need quotes
gt;because I used a numeric password.
gt;
gt;Hans
gt;
gt;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

Funny, how ambiguous language can be. :-)

You are most welcome, George.

Und viele Gruesse aus dem kalten Deutschland!

Hans

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()