Results 1 to 13 of 13

VB Code to restrict opening excel file for certain computer name only

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to restrict opening excel file for certain computer name only

    Hello:

    Please refer to attached file.
    I am trying to put the code in the workbook so that the excel file can be open only if the computer name is as assigned.
    However, it is malfunctioning although i have correct Computer name (User as below) in the code.
    Would appreciate if you can help me with this to solve

    1st set of code is in "ThisWorkbook"
    Private Sub Workbook_Open()
        
         'Unhide all worksheets
        Application.ScreenUpdating = False
        Call XQuit
        Call ShowAllSheets
        
        Application.ScreenUpdating = True
    End Sub
    Below code in Module

    Sub XQuit()
        Dim User As String, passWord As String
        User = "NBook;" 'separate with ";"
        
        
        If CBool(InStr(1, User, Environ("computername") & ";")) Then
        
        MsgBox ("Workbook is enabled")
        
        
             'workbbok is enabled show its content
        Else
        MsgBox "You are trying to access restricted panel.", vbCritical, "Access Denied"
        
            passWord = InputBox("Password for Manual Access:", vbCritical, "Automatic Access Denied -  Last Chance")
            If passWord <> "1111" Then Application.Quit
        
        
        
        End If
    End Sub
    
    Sub ShowAllSheets()
         'Show all worksheets except the macro welcome page
         
        Dim ws As Worksheet
         
        For Each ws In ThisWorkbook.Worksheets
            If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVisible
        Next ws
         
        Worksheets("Macros").Visible = xlSheetVeryHidden
    End Sub
    Sub HideAllSheets()
         'Hide all worksheets except the macro welcome page
        Dim ws As Worksheet
         
        Worksheets("Macros").Visible = xlSheetVisible
         
        For Each ws In ThisWorkbook.Worksheets
            If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVeryHidden
        Next ws
         
        'Worksheets(WelcomePage).Activate
        Worksheets("Macros").Activate
        
    End Sub
    Let me know if you have any questions.
    Thanks.
    Riz
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 03-13-2015, 01:36 PM
  2. vba code for opening excel file and insert a new column in exisiting excel file
    By saratu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2014, 02:55 PM
  3. Replies: 1
    Last Post: 06-30-2012, 02:03 PM
  4. Macro to not allow opening of file only on certain computer if it is already opened
    By Repent34 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-04-2011, 05:41 PM
  5. [SOLVED] restrict a user from opening a dbf file from excel?
    By WyldX in forum Excel General
    Replies: 0
    Last Post: 01-18-2006, 09:45 AM
  6. Replies: 3
    Last Post: 11-29-2005, 04:55 PM
  7. Replies: 1
    Last Post: 01-06-2005, 10:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1