Hello Forum,
I should begin by informing you all that I have implemented a method which tackles the so-called 'Force Enabling of Macros' dilema. A post thread on this site provided a solution whereby a generic sheet is the only visible sheet upon opening the workbook with a text message stating that the 'Enable Content' button must be selected to view the workbook's main content. Once the user clicks the 'Enable Content', a macro hides the prompt sheet and unhides the main content sheet. A new issue is that it has become neccessary to only allow access to a predetermined group who will be given unique usernames and passwords.
I have created a user form that is opened with the 'On Open Workbook' event. It has two text boxes, one for username entry and the second for password entry. These user entries are delivered to two cells in a veryhidden spreadsheet which includes a column containing usernames and a column containing corresponding user passwords. This sheet is set up so that these columns are used in connection with the cells referencing the user entry inputs. The two vlookup cells in the sheet are nested within an iferror formula which will return the value of the match, be it username or password, if there is a correct match, or the value, 'No Match', if vlookup returns an error. Ultimately, a third 'IF' formula cell checks whether both of the vlookup cells matched; if both matched then the formula returns the value, 'Yes' and if both didn't match, the formula returns the value, 'No'.
The issue arises when this third 'Yes/No' formula cell is used as the determining value for a VBA module which is pivotal in allowing access to the main workbook content sheet.
Private Sub Workbook_Open()
Dim Determinant As String
Determinant = Worksheets("Authentication").Range("E1") 'link to the Yes/No formula cell
Authentication.Show 'name of the user form
Application.ScreenUpdating = True
If Determinant = "No" Then MsgBox "I am Sorry, but the username and password that you entered do not match the credentials specified in our records." _
& " If you feel this is in error, please contact the Office of Institutional Research and Analysys.", vbOKOnly, "Error"
If Determinant = "Yes" Then Worksheets("Definitions").Visible = True 'A supplementary variable definition sheet
If Determinant = "Yes" Then Worksheets("Pivot Table").Visible = True 'The main content sheet
If Determinant = "Yes" Then Worksheets("Welcome").Visible = xlVeryHidden 'The prompt sheet
If Determinant = "Yes" Then Worksheets("Pivot Table").Activate
If Determinant = "Yes" Then MsgBox "CAUTION: It is recommended that you close any other Microsoft Office documents before using the interactive features of this document." _
& " This document is macro-enabled and may cause unexpected changes in other open Microsoft Office documents.", vbOKOnly, "Important!"
End Sub
The code does not cause an error, but does not perform reliably, i.e. it will sometimes allow an incorrect username and password into the main content, and sometimes deny access to a correct username and password?
Any help/alternatives will be greatly apprecaited,
Thanks
Bookmarks