+ Reply to Thread
Results 1 to 4 of 4

My Code For Protecting Isn't working

Hybrid View

mingauhauck My Code For Protecting Isn't... 11-25-2020, 07:49 PM
vba_php Re: My Code For Protecting... 11-26-2020, 12:09 AM
Andy Pope Re: My Code For Protecting... 11-26-2020, 03:50 AM
vba_php Re: My Code For Protecting... 11-26-2020, 04:32 AM
  1. #1
    Registered User
    Join Date
    11-25-2020
    Location
    Brazil
    MS-Off Ver
    Office365
    Posts
    1

    My Code For Protecting Isn't working

    I'm trying to make it work:

    But for some reason it's not working. There is a 1004 error at:


    Sheets("Formulario de Nova Contratacao").Protect Password:="3,1415", DrawingObjects:=True, Contents:=True, Scenario:=True
    And the button are not working either. Even if i cancel the protection and unprotection functions.

    Don't know what it's happening.

    Function Bloquear()
    
    ' Bloqueia toda a planilha
    
    ' Para não bloqueá-la: digitar manut no campo B8
    
    
    
    Application.ScreenUpdating = False
    
    
    
    If Sheets("Formulario de Nova Contratacao").Range("B8") = "manut" Then Exit Function
    
    
    
    Sheets("Formulario de Nova Contratacao").Protect Password:="3,1415", DrawingObjects:=True, Contents:=True, Scenario:=True
    
    ThisWorkbook.Protect
    
    
    
    End Function
    
    Function Desbloquear()
    
    ' Desbloqueia toda a planilha
    
    
    
    Worksheets("Formulario de Nova Contratacao").Unprotect Password:="3,1415"
    
    ThisWorkbook.Unprotect
    
    
    
    End Function
    
    
    
    Private Sub OptionButton1_Click()
    
    ' Bandeira do Brasil: Mostra os Campos 9 e 10 (linhas 24 a 26)
    
    ' Campo 14 (Linhas 35 a 37)
    
    ' Campo 19.1 (Linhas 71 a 84)
    
    ' Esconde os Campos 4 e 5 (Linhas 10 a 12)
    
    
    
    Call Desbloquear
    
    
    
    If OptionButton1.Value = True Then
    
    
    
    Rows("10:12").Hidden = True
    
    Rows("24:26").Hidden = False
    
    Rows("35:37").Hidden = False
    
    Rows("71:84").Hidden = False
    
    
    
    Call Bloquear
    
    
    
    End If
    
    
    
    End Sub
    
    
    
    Private Sub OptionButton2_Click()
    
    ' Bandeira do Brasil: Mostra os Campos 9 e 10 (linhas 24 a 26)
    
    ' Campo 14 (Linhas 35 a 37)
    
    ' Campo 19.1 (Linhas 71 a 84)
    
    ' Esconde os Campos 4 e 5 (Linhas 10 a 12)
    
    
    
    Call Desbloquear
    
    
    
    If OptionButton1.Value = True Then
    
    
    
    Rows("10:12").Hidden = False
    
    Rows("24:26").Hidden = True
    
    Rows("35:37").Hidden = True
    
    Rows("71:84").Hidden = True
    
    
    
    Call Bloquear
    
    
    
    End If
    
    
    
    End Sub
    Last edited by 6StringJazzer; 11-25-2020 at 08:00 PM. Reason: Please read the rules and use code tags

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: My Code For Protecting Isn't working

    1004 is application defined or object defined error. with the method you are using, it could be any number of things. VBA isn't the greatest languages in the world, and is completely inconsistent in many ways. MS's fault, totally. see these first:

    https://www.google.com/search?q=excel+vba+.Protect+

    https://docs.microsoft.com/en-us/off...ksheet.protect

    https://www.google.com/search?q=vba+excel+1004+error

    https://stackoverflow.com/questions/...or-when-select

    then, maybe try all of the following as possible fixes
    PHP Code: 
    Sheets("Formulario de Nova Contratacao").Protect Password:="3,1415"DrawingObjects:=-1Contents:=-1Scenario:=-
    PHP Code: 
    Sheets("Formulario de Nova Contratacao").Protect Password:="3,1415"TrueTrueTrue 
    PHP Code: 
    Sheets("Formulario de Nova Contratacao").Protect "3,1415"TrueTrueTrue 
    furthermore, are you sure the code is the issue? If there is no sheet called Formulario de Nova Contratacao, that would also cause the error, obviously. no defined object in that case.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: My Code For Protecting Isn't working

    The named argument is Scenarios, plural.

    worksheets("Formulario de Nova Contratacao").Protect Password:="3,1415", DrawingObjects:=True, Contents:=True, Scenarios:=True
    Cheers
    Andy
    www.andypope.info

  4. #4
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: My Code For Protecting Isn't working

    wow. nice catch andy!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Help: Macro NOT Working After Protecting Sheet
    By g1987 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2020, 09:02 AM
  2. [SOLVED] Protecting Sheet stops searching from working
    By VisionSmart in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-05-2018, 12:46 AM
  3. [SOLVED] Protect Sheet not working after protecting workbook?
    By Nonie in forum Excel General
    Replies: 1
    Last Post: 06-24-2014, 10:29 PM
  4. [SOLVED] How to get control back from rogue code that keeps protecting my sheet wwhen I'm working
    By nje in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-21-2013, 09:14 AM
  5. [SOLVED] Protecting all but one worksheet macro not working
    By Shauna in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-04-2012, 01:24 PM
  6. Password protecting a workbook prevents Macros from working.
    By PeterMcCarthy in forum Excel General
    Replies: 3
    Last Post: 02-07-2012, 07:01 PM
  7. [SOLVED] up down arrows not working after protecting sheet
    By Computer Man 678 in forum Excel General
    Replies: 2
    Last Post: 12-04-2005, 07:15 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