Results 1 to 5 of 5

Enforcing the end user to enable macros

Threaded View

IPDaily Enforcing the end user to... 07-18-2012, 02:36 AM
TMS Re: Enforcing the end user to... 07-18-2012, 03:02 AM
IPDaily Re: Enforcing the end user to... 08-20-2012, 10:40 PM
Cutter Re: Enforcing the end user to... 08-20-2012, 10:48 PM
TMS Re: Enforcing the end user to... 08-21-2012, 10:17 AM
  1. #1
    Registered User
    Join Date
    07-18-2012
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010 & 2003
    Posts
    4

    Enforcing the end user to enable macros

    Hi

    My intentions is to prevent the workbook from being used if the macros are not enabled. If the workbook macros are not enabled then a warning is displayed and hiding all other sheets and instructing the user to close and re-open the workbook and enable the macros.

    I am getting a Run-time error '1004' on exit and start up "Unable to set the Visible property of the Sheets class"
    When I Debug, the highlighted area that is identified is the Sheet Array section for both private subs.

    This is what I have at the minute.

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    ' Turn off Screen Updating
        Application.ScreenUpdating = False
    
    'Unlock Workbook
        ActiveWorkbook.Unprotect Password:="XXXXX"
    
    'Unlock Sheets
    Dim wsWorksheet As Worksheet
    For Each wsWorksheet In ActiveWorkbook.Worksheets
    wsWorksheet.Unprotect Password:="XXXXX"
    Next
    
    'Unhide Sheet
    Sheets("Warning").Visible = True
    
    'Hide Sheets
    Sheets(Array("SMU HR Meter Entry", "Service Schedule", _
            "Ancillary Schedule", "Light Vehicle Schedule", "Oil Sampling Schedule", _
            "Drifter Percussion Hours", "Project 32 Valve Sets", " EOM HRS Data", _
            "Schedule Major Service Table", "Master Sheet")).Visible = xlVeryHidden
    
    'Lock Sheets
    For Each wsWorksheet In ActiveWorkbook.Worksheets
    wsWorksheet.Protect Password:="XXXXX"
    Next
    
    'Turn on Screen Updating
        Application.ScreenUpdating = True
    
    'Lock Workbook
        ActiveWorkbook.Protect Password:="XXXXX"
    
    End Sub
    
    Private Sub Workbook_Open()
    
    ' Turn off Screen Updating
        Application.ScreenUpdating = False
    
    'Unlock Workbook
        ActiveWorkbook.Unprotect Password:="XXXXX"
        
    'Unlock Sheets
    Dim wsWorksheet As Worksheet
    For Each wsWorksheet In ActiveWorkbook.Worksheets
    wsWorksheet.Unprotect Password:="XXXXX"
    Next
    
    'Unhide Sheets
    Sheets(Array("SMU HR Meter Entry", "Service Schedule", _
            "Ancillary Schedule", "Light Vehicle Schedule", "Oil Sampling Schedule", _
            "Drifter Percussion Hours", "Project 32 Valve Sets", " EOM HRS Data", _
            "Schedule Major Service Table", "Master Sheet")).Visible = True
    
    'Hide Sheet
    Sheets("Warning").Visible = xlVeryHidden
    
    'Lock Sheets
    For Each wsWorksheet In ActiveWorkbook.Worksheets
    wsWorksheet.Protect Password:="XXXXX"
    Next
    
    'Lock Workbook
        ActiveWorkbook.Protect Password:="XXXXX"
        
    'Turn on Screen Updating
        Application.ScreenUpdating = True
    
    End Sub

    P.S. I'm new, self taught and have been at this for no longer than 4 weeks.............be gentle!

    P.S.S. Note attached file is my test file, this is not my master.

    Cheers
    Last edited by IPDaily; 07-24-2012 at 08:13 AM.

Thread Information

Users Browsing this Thread

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

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