Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
GA
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.misc
Maurice
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.misc
flummi
 
Posts: n/a
Default Include a password in VB code.

Su

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   Report Post  
Posted to microsoft.public.excel.misc
George Avery
 
Posts: n/a
Default Include a password in VB code.

flummi wrote:

Su


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   Report Post  
Posted to microsoft.public.excel.misc
flummi
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.misc
GA
 
Posts: n/a
Default Include a password in VB code.

On 22 Mar 2006 05:38:29 -0800, "flummi" 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   Report Post  
Posted to microsoft.public.excel.misc
flummi
 
Posts: n/a
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very Novice Excel user with security question Ralph Malph Excel Discussion (Misc queries) 5 March 23rd 06 06:33 PM
Worksheet Protection Angeline Excel Discussion (Misc queries) 3 March 20th 06 12:49 PM
VLOOKUP for Zip Code Ranges JerseyJR Excel Worksheet Functions 2 September 6th 05 06:37 PM
Using other workbooks.. DavidMunday Excel Worksheet Functions 2 July 1st 05 07:35 AM
password protect vba code greg Excel Discussion (Misc queries) 3 December 8th 04 04:03 PM


All times are GMT +1. The time now is 03:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"