Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating a Userform

I have an excel file where I call a "Workbook_Open" subroutine from the
"ThisWorkbook" subheading in the Mircosoft Excel Objects. Before I call
this subroutine, I want to hide all of my sheets (1, 2, and 3) and then
I want to call a userform that prompts for a username and password. If
the username and password are correct, then the userform should call my
"Workbook_Open" subroutine and unhide the hidden sheets.

I had some code I saw on another topic, but I couldn't get it to call
my subroutine ("Workbook_Open") after it validated my username and
password.

Anybody have a suggestion here. I can make the userform but I'm not
sure where to insert the code.

Thanks for the help!

Ben

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a Userform


Hello MaxRoberts22,

The UserForm must be called from the Workbook_Open event, not the
reverse. The Workbook_Open event can not be triggered from VBA, but
only by Excel opening the workbook. At the start of the event hide,
Excel will display how the workbook was saved last, If the worksheets
were visible, the worksheets will be displayed. They will be hidden
once the code runs. To have the workbook come up "blank", hide the
worksheets and save the workbook in the Workbook_BeforeClose event.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=507791

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating a Userform

So you're saying start the Workbook_Open subroutine by calling the
userform_activate subroutine in the userform? Or should there be two
subroutines in the Workbook_Open; one to call the userform and then the
userform will call the second Workbook_Open subroutine (if that makes
any sense)?

Can you give me a condensed version of what this might look like in the
work book? This is the code I have written for the userform:

Public cntr As Integer

Private Sub CommandButton1_Click()
ValidatePWD
End Sub

Private Sub UserForm_Activate()
cntr = 0
Label1.Caption = "Username & Password Required"
Label2.Caption = "Username:"
Label3.Caption = "Password:"
TextBox2.PasswordChar = "*"
CommandButton1.Caption = "Open Workbook"
End Sub

Private Sub ValidatePWD()
If TextBox1.Value = "username" And TextBox2.Value = "password" Then
UserForm1.Hide
Call Workbook_Open
Else
cntr = cntr + 1
If cntr 3 Then
MsgBox "Sorry...wrong password...goodbye"
ThisWorkbook.Saved = True
ThisWorkbook.Close
Else
MsgBox "Attempt #" & cntr & vbCrLf & "Incorrect UserName
and/or Password entered"
End If
End If
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox Prompt:=" Sorry but I can't let you do that. "
End If
End Sub

I wanna call the Workbook_Open function from this userfrom_activate.
You're saying I cannot do this?

Ben

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Creating a Userform

Nevermind, I got it to work. Thanks for the help!

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
Creating a lookup in a userform BJ&theBear Excel Discussion (Misc queries) 4 March 17th 10 06:51 PM
Creating first ever userform but not going how I wanted WhiteFalcon Excel Programming 4 May 11th 05 12:00 AM
Creating a Userform using code trini Excel Programming 1 March 5th 05 11:15 PM
Creating Temporary Userform with checkboxes [email protected] Excel Programming 1 February 13th 05 01:39 PM
Need help creating a userform with optionbuttons TB[_2_] Excel Programming 2 July 21st 03 02:16 PM


All times are GMT +1. The time now is 03:55 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"