0

I would like to create a macro that opens as soon as the excel file is opened, and does not allow any action until authentication is made.

The idea is that the login macro, when authentication succeeds, will call another macro that makes a connection to a database and calls a procedure that will populate the sheets, which I also have doubts about how to make, since it has to connect to a database.

The authentication process needs to read the information on a user form and be able to send it as a parameter to a procedure in SQL so that it returns whether the authentication was successful or not.

Any suggestions? Thank you in advance!

Community
  • 1
  • 1
virginia_c
  • 3
  • 2
  • 9

2 Answers2

4

You need to hook into the Workbook_Open event

Private Sub Workbook_Open()

End Sub

That goes into the Workbook module. Put your authentication macro in that sub and it will fire as soon as the workbook is opened.

Justin Self
  • 6,137
  • 3
  • 33
  • 48
0

The way to call a macro at startup is as jstnS described the use of Workbook_Open().

Yet, your question is a bit unclear about the authentication because if you want to store the login / password inside Excel, you will have to think about it.

As you can't really protect VBA code (discussed in this thread and this thread), your login within Excel won't be really secured.

Actually, you could try to add login / password in a very hidden worksheet (VBA hidden) and hash the password of the user (provided that the hash can't be used as a password by itself).
The latter issue could be an interesting question.

Community
  • 1
  • 1
JMax
  • 26,109
  • 12
  • 69
  • 88
  • thank you for the answer! protection of the information isn't soo much of a concern in this case, but I need this authentication so taht the person can be identified, and i can call another macro when the person clicks on the login button that calls a procedure in our database that gets the user's company and then fill out the tables accordingly ! – virginia_c Nov 29 '11 at 11:34
  • 1
    Is there a 1-1 relationship with the computer log in and the excel workbook log in? If so, what about just grabbing the user who is currently logged in Windows? This can be done in VBA. – Justin Self Nov 29 '11 at 16:16