![]() |
Form VBA
I'm trying to create a macro that will protect and unprotect 10 sheets in a workbook. i have the code to protect etc. i'm having a problem he i created a form named frmPassword where i have a text field called My_Password. what code would i use to open up that form and enter in a password, then when i click ok to assign whatever was in My_Password to a variable called My_Pass. I tried My_Pass=frmPassword.My_Password but that doesnt work, probably because i never opened the form. any help? -- tkaplan ------------------------------------------------------------------------ tkaplan's Profile: http://www.excelforum.com/member.php...o&userid=22987 View this thread: http://www.excelforum.com/showthread...hreadid=376377 |
Form VBA
1) Wherever you want to open the form from:
Load frmPassword frmPassword.Show Unload frmPassword 2) In the VB editor, Insert a Module (InsertModule), if you don't already have one. This needs to be in a General Module NOT a Form, Workbook, Worksheet, Class or other Object module. Place the following at the top (right below any Option Explicit statement and before any subs or functions): Public My_Pass as String Give the module a name and save it: 3) In the Click event of your "OK" button on frmPassword: My_Pass=Me.My_Password frmPassword.Hide (where My_Password is the name of the textbox on frmPassword) The value entered on frmPassword should now be available to you throughout the project in any VBA code as My_Pass. HTH, -- George Nicholson Remove 'Junk' from return address. "tkaplan" wrote in message ... I'm trying to create a macro that will protect and unprotect 10 sheets in a workbook. i have the code to protect etc. i'm having a problem he i created a form named frmPassword where i have a text field called My_Password. what code would i use to open up that form and enter in a password, then when i click ok to assign whatever was in My_Password to a variable called My_Pass. I tried My_Pass=frmPassword.My_Password but that doesnt work, probably because i never opened the form. any help? -- tkaplan ------------------------------------------------------------------------ tkaplan's Profile: http://www.excelforum.com/member.php...o&userid=22987 View this thread: http://www.excelforum.com/showthread...hreadid=376377 |
All times are GMT +1. The time now is 09:51 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com