Results 1 to 8 of 8

Thread: warning at startup
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jul 2019
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default warning at startup

    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

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,311
    Post Thanks / Like
    Mentioned
    72 Post(s)
    Tagged
    14 Thread(s)

    Default Re: warning at startup

    You mean it appears only on the first sheet?
    Regards Dante Amor

  3. #3
    New Member
    Join Date
    Jul 2019
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: warning at startup

    no sheet other than

    If fogli.Name <> "AA" And fogli.Name <> "BB" And fogli.Name <> "CC" And fogli.Name <> "DD" Then

  4. #4
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,311
    Post Thanks / Like
    Mentioned
    72 Post(s)
    Tagged
    14 Thread(s)

    Default Re: warning at startup

    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?
    Regards Dante Amor

  5. #5
    New Member
    Join Date
    Jul 2019
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: warning at startup

    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

  6. #6
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,311
    Post Thanks / Like
    Mentioned
    72 Post(s)
    Tagged
    14 Thread(s)

    Default Re: warning at startup

    Quote Originally Posted by john_cash View Post
    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
       ThisWorkbook.Save
     Application.ScreenUpdating = True
     '-----------------------------------------------
              
    End Sub
    Last edited by DanteAmor; Aug 1st, 2019 at 07:05 PM.
    Regards Dante Amor

  7. #7
    New Member
    Join Date
    Jul 2019
    Posts
    17
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: warning at startup

    Hi danteamor.
    Thanks for the added function.
    I have to try next week in my office.
    I salute you and thanks again
    john

  8. #8
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    6,311
    Post Thanks / Like
    Mentioned
    72 Post(s)
    Tagged
    14 Thread(s)

    Default Re: warning at startup

    ok, let me know if you have any doubt.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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