| 
		 
		
		 | 
	
 | 
 
 
 | 
	
		| 
			 
		 | 
	
    
		| 
			 
				
				
			 
		 | 
	
	
	
		| 
			 
				Excel
			 
		 | 
		
			 
				Force User to Enable Macros
			 
		 | 
		
			 
				 
			
		 | 
	
	
		| 
			 
				Ease of Use
			 
		 | 
		
			 
				Easy
			 
		 | 
	
	
		| 
			 
				Version tested with
			 
		 | 
		
			 
				2000, 2003 
			 
		 | 
	
	
		| 
			 
				Submitted by:
			 
		 | 
		
			 
				johnske
			 
		 | 
	
		
		| 
			 
				Description:
		  | 
		
			 
					If a user does not have macros enabled, when the workbook is opened a sheet prompting them to enable macros is shown, all other sheets are hidden. 
			 
		 | 
	
	
		| 
			 
				Discussion:
			 
		 | 
		
			 
				When a workbook contains VBA procedures it is important that macros be enabled. This procedure forces the user to enable macros. (Upgraded 14 November 2006 to cater for chartsheets as well as worksheets) 
			 
		 | 
	
	
	
		| 
			 
				Code:
			 
		 | 
		
			 
				 
					instructions for use
				
			 
		 | 
	
	
		
			
			Option Explicit 
 
Private Sub Workbook_Open() 
     
    With Application 
         
        .EnableCancelKey = xlDisabled 
        .ScreenUpdating = False 
         
        Call UnhideSheets 
         
        .ScreenUpdating = True 
         
        .EnableCancelKey = xlInterrupt 
    End With 
     
End Sub 
 
Private Sub UnhideSheets() 
     
    Dim Sheet As Object 
     
    For Each Sheet In Sheets 
        If Not Sheet.Name = "Prompt" Then 
            Sheet.Visible = xlSheetVisible 
        End If 
    Next 
     
    Sheets("Prompt").Visible = xlSheetVeryHidden 
     
    Application.Goto Worksheets(1).[A1], True 
     
    Set Sheet = Nothing 
    ActiveWorkbook.Saved = True 
     
End Sub 
 
Private Sub Workbook_BeforeClose(Cancel As Boolean) 
    With Application 
        .EnableCancelKey = xlDisabled 
        .ScreenUpdating = False 
         
        Call HideSheets 
         
        .ScreenUpdating = True 
        .EnableCancelKey = xlInterrupt 
    End With 
End Sub 
 
Private Sub HideSheets() 
     
    Dim Sheet As Object 
     
    With Sheets("Prompt") 
         
         
         
         
         
        If ThisWorkbook.Saved = True Then .[A100] = "Saved" 
         
        .Visible = xlSheetVisible 
         
        For Each Sheet In Sheets 
            If Not Sheet.Name = "Prompt" Then 
                Sheet.Visible = xlSheetVeryHidden 
            End If 
        Next 
         
        If .[A100] = "Saved" Then 
            .[A100].ClearContents 
            ThisWorkbook.Save 
        End If 
         
        Set Sheet = Nothing 
    End With 
     
End Sub 
 
 
			 
		 | 
	
	
		| 
			 
			
				How to use:
			 
		 | 
		
			 
				 - Open an Excel workbook 
 - Select Tools/Macro/Visual Basic Editor 
 - In the VBE window, select View/Project Explorer 
 - Select the ThisWorkbook module 
 - Copy and paste the code above into this Module 
 - Now select File/Close and Return To Microsoft Excel 
 - Dont forget to save your changes...
 - Name one of your sheets "Prompt"
   
			
		 | 
	
	
		| 
			 
				Test the code:
			 
		 | 
		
			 
				 - If you have macros enabled, disable them then close and open the workbook.
   
			
		 | 
	
	
		| 
			 
				Sample File:
			 
		 | 
		
			 
					ForceMacros_New.zip 10.29KB 
			 
		 | 
	
    
		| 
			 
				Approved by mdmackillop
			 
		 | 
	
    
		| 
			 
				
			 
			
			 
			 
			
This entry has been viewed 1301 times.
 
		 | 
	
    
		| 
			 
				
				
			 
		 |