warning at startup

john_cash

New Member
Joined
Jul 30, 2019
Messages
23
Hello
the macro in Private Sub Workbook_BeforeClose to the close inserts the writing in the enabled sheets:

"you need to enable macros to view this workbook"
"devi attivare le macro per visualizzare questo workbook"

when the workbook starts, if the macros are activated the word disappears.
Is it possible that at the end of the workbook the writing does not appear but only at startup and then disappears if the macros are activated?
I hope I have explained.


Code:
Option Explicit

Private Sub Workbook_Open()
    
    
     Dim nomefoglio As Variant
     Dim Urec   As String
    
  '-------------------------------------------
 'se non attivate le macro il workbook resta bloccato
     Dim fogli As Worksheet
    
    Application.ScreenUpdating = False
    
    'For Each fogli In Worksheets
     For Each fogli In ThisWorkbook.Sheets
      If fogli.Name <> "AA" And fogli.Name <> "BB" And fogli.Name <> "CC" And fogli.Name <> "DD" Then
       fogli.Unprotect "987654"
       fogli.Range("E1:H1").ClearContents
       fogli.Unprotect "987654"
       End If
    Next
    
   Application.ScreenUpdating = True
 '-------------------------------------------
                  
  
End Sub



Private Sub Workbook_BeforeClose(Cancel As Boolean)
  
    Dim nomefoglio As Variant
    Dim Urec   As String
      
  '-----------------------------------------------
 'se non attivate le macro il workbook resta bloccato
    Dim fogli As Worksheet
 
 Application.ScreenUpdating = False
    'For Each fogli In Worksheets
     For Each fogli In ThisWorkbook.Sheets
      If fogli.Name <> "AA" And fogli.Name <> "BB" And fogli.Name <> "CC" And fogli.Name <> "DD" Then
       fogli.Unprotect "987654"
     fogli.Range("E1:H1").Value = "devi attivare le macro per visualizzare questo workbook"
       fogli.Protect "987654"
       End If
    Next

 Application.ScreenUpdating = True
 '-----------------------------------------------
          
End Sub

john
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
no sheet other than

If fogli.Name <> "AA" And fogli.Name <> "BB" And fogli.Name <> "CC" And fogli.Name <> "DD" Then
 
Upvote 0
Sorry, but I don't understand.
I tested your code and it works.
What is the problem or what change do you want to make?
 
Upvote 0
Is it possible that at the close of the workbook the writing:

"you need to enable macros to view this workbook"
"devi attivare le macro per visualizzare questo workbook"

does not appear but only at open the workbook and then disappears if the macros are activated?

john
 
Upvote 0
Is it possible that at the close of the workbook the writing:

"you need to enable macros to view this workbook"
"devi attivare le macro per visualizzare questo workbook"

does not appear but only at open the workbook and then disappears if the macros are activated?

john

All I see is that the file needs to be saved.


Try this,

Add this line in Workbook_BeforeClose

ThisWorkbook.Save

Code:
Option Explicit


Private Sub Workbook_Open()
    
    
     Dim nomefoglio As Variant
     Dim Urec   As String
    
  '-------------------------------------------
 'se non attivate le macro il workbook resta bloccato
     Dim fogli As Worksheet
    
    Application.ScreenUpdating = False
    
    'For Each fogli In Worksheets
     For Each fogli In ThisWorkbook.Sheets
      If fogli.Name <> "AA" And fogli.Name <> "BB" And fogli.Name <> "CC" And fogli.Name <> "DD" Then
       fogli.Unprotect "987654"
       fogli.Range("E1:H1").ClearContents
       fogli.Unprotect "987654"
       End If
    Next
    
   Application.ScreenUpdating = True
 '-------------------------------------------
                  
  
End Sub






Private Sub Workbook_BeforeClose(Cancel As Boolean)
  
    Dim nomefoglio As Variant
    Dim Urec   As String
      
  '-----------------------------------------------
 'se non attivate le macro il workbook resta bloccato
    Dim fogli As Worksheet
 
 Application.ScreenUpdating = False
    'For Each fogli In Worksheets
     For Each fogli In ThisWorkbook.Sheets
      If fogli.Name <> "AA" And fogli.Name <> "BB" And fogli.Name <> "CC" And fogli.Name <> "DD" Then
       fogli.Unprotect "987654"
     fogli.Range("E1:H1").Value = "devi attivare le macro per visualizzare questo workbook"
       fogli.Protect "987654"
       End If
    Next
[COLOR=#ff0000][B]   ThisWorkbook.Save[/B][/COLOR]
 Application.ScreenUpdating = True
 '-----------------------------------------------
          
End Sub
 
Last edited:
Upvote 0
Hi danteamor.
Thanks for the added function.
I have to try next week in my office.
I salute you and thanks again
john
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,705
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top