Home |
Search |
Today's Posts |
#14
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Worked why my message pop up was not appearing, I had turned off
macro's!!!!!! Sean wrote: Mike I took your Splash screen on board, I've got it to Hide all sheets etc, but now my Message pop up window doesn't appear and neither does my info page when its a permitted user. What have I done wrong? Both codes below are in ThisWorkbook Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim sh As Worksheet For Each ws In Worksheets If ws.Name = "Splash" Then ws.Visible = True Else ws.Visible = False End If Next End Sub Private Sub Workbook_Open() Dim sh As Worksheet With Application If .UserName = "John Doe" Or .UserName = "Joe Bloggs" Then ThisWorkbook.Sheets("info").Visible ThisWorkbook.Sheets("info").Select Else ThisWorkbook.Sheets("Splash").Select MsgBox "You are NOT Permitted to access this File " & vbCr & _ "" & vbCr & _ "Please Contact Joe Bloggs at " & vbCr & _ "" & vbCr & _ "ABC Group +09992 1 25480000" ThisWorkbook.Sheets("info").Select Application.DisplayAlerts = False ThisWorkbook.Close False End If End With End Sub Mike Fogleman wrote: As Dave Peterson pointed out, Excel is an easy nut to crack for those who really want to. Nothing is truly safe in Excel from those who persist. That said, the theory behind the Splash sheet is to hide all worksheets except the Splash, when the workbook closes. If the workbook is opened with macros disabled, then the Splash sheet is the only one visible and the macro to unhide the other sheets cannot run. Create a worksheet named "Splash" and if you want, put "ACCESS DENIED!" in the middle with large font. Once that is done use the following code in ThisWorkbook module. Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim ws As Worksheet For Each ws In Worksheets If ws.Name = "Splash" Then ws.Visible = True Else ws.Visible = False End If Next End Sub Modify the Workbook_Open event as follows: MsgBox no longer needed. Private Sub Workbook_Open() Dim myArray As Variant Dim arName As String Dim ws As Worksheet arName = "MyUsers" myArray = ThisWorkbook.Names(arName).RefersToRange.Value With Application If IsError(.WorksheetFunction.Match(.UserName, myArray, 0)) Then 'MsgBox "You are NOT permitted to Open this File ! !" Application.DisplayAlerts = False ThisWorkbook.Close False Else For Each ws In Worksheets ws.Visible = True Next Worksheets("Splash").Visible = False Worksheets("Users").Visible = False Worksheets("Sheet1").Activate End If End With Application.DisplayAlerts = True End Sub Mike F "Sean" wrote in message oups.com... Thanks Mike, it works great. How would I include that it opens on a Blank Sheet, say Sheet1 if I get the message "You are not permitted" etc and if you don't it goes to Sheet2 A1 Slight problem I see is that a non-permitted user may see info displayed on the screen and it won't close until they click ok to the message Mike Fogleman wrote: Right you are! Parentheses wrong order. Private Sub Workbook_Open() Dim myArray As Variant Dim arName As String arName = "MyUsers" myArray = ThisWorkbook.Names(arName).RefersToRange.Value With Application If IsError(.Match(.UserName, myArray, 0)) Then MsgBox "You are NOT permitted to Open this File ! !" Application.DisplayAlerts = False Application.Quit Else End If End With End Sub Mike F "Sean" wrote in message oups.com... Thanks Mike, I'm getting a Syntax error on line If IsError(.Match(.UserName ), myArray, 0)) Then Mike Fogleman wrote: One way is to put the list of users in the workbook somewhere, ie, a worksheet named "Users" The worksheet can be hidden from view but easily accessed to update the list without changing the code. Make the list a Named Range like "MyUsers" (not the same as a worksheet name). This list will be added to an array and will be compared to the .UserName of the person trying to open the workbook. Private Sub Workbook_Open() Dim myArray As Variant Dim arName As String arName = "MyUsers" myArray = ThisWorkbook.Names(arName).RefersToRange.Value With Application If IsError(.Match(.UserName ), myArray, 0)) Then MsgBox "You are NOT permitted to Open this File ! !", xlExclamation Application.DisplayAlerts = False Application.Quit Else End If End With End Sub This is untested, so try it out or modify as needed. Mike F "Sean" wrote in message oups.com... Is it possible to deny access to open an Excel file except to specified user? I assume this code as well as the user access list would go within the ThisWorksheet. In that on opening the file, it would compare the Computer user logged in to the list and if "Joe Bloggs" or "Joe Public" is listed it would allow it to open, otherwise a message "Go Away" would appear and file would not open Is this possible, or is it way too advanced? Thanks |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Deny/Allow for certain range. | Excel Discussion (Misc queries) | |||
deny printing for certain blank cells | Excel Worksheet Functions | |||
Deny file access if user declines macros? | Excel Discussion (Misc queries) | |||
limit or deny opening other files | Excel Programming | |||
Forcing Macros to Run (Else Deny Access to Workbook) | Excel Programming |