Notifications
Clear all

ERRO DE FILTRO AVANÇADO EM PLANILHA PROTEGIDA

9 Posts
3 Usuários
0 Reactions
2,410 Visualizações
(@anacletotranstusa)
Posts: 64
Estimable Member
Topic starter
 

Olá Pessoal,
Modelo anexo é um simples modelo só pra exemplificar meu problema.
Eu tenho uma estrutura bem mais complexa e estou tentando fazer um filtro avançado com uma aba protegida e está gerando um erro na macro, no modelo anexo a aba consulta está protegida não tem senha cadastrada só está protegida, nela contem um filtro avançado que busca informações da aba Base.
Se alguém tiver uma ideia de resolver agradeço!
Abraço!

 
Postado : 14/07/2017 4:31 am
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

anacletotranstusa,

Bom dia!

Assim.

 
Postado : 14/07/2017 5:56 am
(@anacletotranstusa)
Posts: 64
Estimable Member
Topic starter
 

Olá Wagner!

Seria isso mesmo, no entanto deixei sem senha para facilitar o entendimento, mas precisaria incluir uma senha, pode ser uma senha padrão, teria como?
Da forma que está se eu proteger com senha ao clicar no botão filtrar abre uma caixa para digitar a senha.
Desde já agradeço sua atenção!
Abraço!

 
Postado : 14/07/2017 6:18 am
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

Sim, pode.

Basta você ver, no próprio help do VBA, que existe um parâmetro chamado Password. Estude o uso da função Protect que você verá.

 
Postado : 14/07/2017 6:26 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Anacleto, porque não simplesmente desprotege e protege a guia?

Sub Filtro()
'
' Filtro Macro
    ActiveSheet.Unprotect '<-- Desproteger
    Range("A3:B4").Select
    Sheets("Base").Columns("A:J").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("A3:B4"), CopyToRange:=Range("Consulta!Extract"), _
        Unique:=False
        
    Range("D8").Select
    ActiveSheet.Protect '<-- Proteger
End Sub

Conforme postagem em:
https://gurudoexcel.com/forum/viewtopic ... 778#p24778
Att

 
Postado : 14/07/2017 7:08 am
(@anacletotranstusa)
Posts: 64
Estimable Member
Topic starter
 

Olá Alexandrevba e wagner,

Na estrutura que estou montando é necessário deixar a aba protegida, pois existem outras células que preciso proteger com senha.
Eu estudei sobre o assunto e fiz a inclusão da senha, a principio funcionou, seria isso mesmo? Eu só inclui o "9928" que seria a senha padrão.
Agradeço a atenção de vocês!

Sub Filtro()
'
' Filtro Macro
    ActiveSheet.Unprotect "9928"
    Range("A3:B4").Select
    Sheets("Base").Columns("A:J").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("A3:B4"), CopyToRange:=Range("Consulta!Extract"), _
        Unique:=False
    Range("D8").Select
    ActiveSheet.Protect "9928"
End Sub
 
Postado : 14/07/2017 7:40 am
(@wagner-morel-vidal-nobre)
Posts: 4063
Famed Member
 

Isso mesmo Anacleto. Parabéns!

 
Postado : 14/07/2017 9:23 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Eu estudei sobre o assunto e fiz a inclusão da senha, a principio funcionou, seria isso mesmo? Eu só inclui o "9928" que seria a senha padrão.

, sim!

Se você leu o material....

expression.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables)
expression Required. An expression that returns a Worksheet object.

Password Optional Variant. A string that specifies a case-sensitive password for the worksheet or workbook. If this argument is omitted, you can unprotect the worksheet or workbook without using a password. Otherwise, you must specify the password to unprotect the worksheet or workbook. If you forget the password, you cannot unprotect the worksheet or workbook. It's a good idea to keep a list of your passwords and their corresponding document names in a safe place.

DrawingObjects Optional Variant. True to protect shapes. The default value is False.

Contents Optional Variant. True to protect contents. For a chart, this protects the entire chart. For a worksheet, this protects the locked cells. The default value is True.

Scenarios Optional Variant. True to protect scenarios. This argument is valid only for worksheets. The default value is True.

UserInterfaceOnly Optional Variant. True to protect the user interface, but not macros. If this argument is omitted, protection applies both to macros and to the user interface.

AllowFormattingCells Optional Variant. True allows the user to format any cell on a protected worksheet. The default value is False.

AllowFormattingColumns Optional Variant. True allows the user to format any column on a protected worksheet. The default value is False.

AllowFormattingRows Optional Variant. True allows the user to format any row on a protected. The default value is False.

AllowInsertingColumns Optional Variant. True allows the user to insert columns on the protected worksheet. The default value is False.

AllowInsertingRows Optional Variant. True allows the user to insert rows on the protected worksheet. The default value is False.

AllowInsertingHyperlinks Optional Variant. True allows the user to insert hyperlinks on the worksheet. The default value is False.

AllowDeletingColumns Optional Variant. True allows the user to delete columns on the protected worksheet, where every cell in the column to be deleted is unlocked. The default value is False.

AllowDeletingRows Optional Variant. True allows the user to delete rows on the protected worksheet, where every cell in the row to be deleted is unlocked. The default value is False.

AllowSorting Optional Variant. True allows the user to sort on the protected worksheet. Every cell in the sort range must be unlocked or unprotected. The default value is False.

AllowFiltering Optional Variant. True allows the user to set filters on the protected worksheet. Users can change filter criteria but can not enable or disable an auto filter. Users can set filters on an existing auto filter. The default value is False.

AllowUsingPivotTables Optional Variant. True allows the user to use pivot table reports on the protected worksheet. The default value is False.

Remarks
If you apply the Protect method with the UserInterfaceOnly argument set to True to a worksheet and then save the workbook, the entire worksheet (not just the interface) will be fully protected when you reopen the workbook. To re-enable the user interface protection after the workbook is opened, you must again apply the Protect method with UserInterfaceOnly set to True.

If changes wanted to be made to a protected worksheet, it is possible to use the Protect method on a protected worksheet if the password is supplied. Also, another method would be to unprotect the worksheet, make the necessary changes, and then protect the worksheet again.

Note 'Unprotected' means the cell may be locked (Format Cells dialog) but is included in a range defined in the Allow Users to Edit Ranges dialog, and the user has unprotected the range with a password or been validated via NT permissions.

Veja que é interessante usar a opção abaixo.
Fonte: http://www.ozgrid.com/VBA/excel-macro-p ... -sheet.htm

serInterfaceOnly Optional Variant. True to protect the user interface, but not macros. If this argument is omitted, protection applies both to macros and to the user interface.

Ou tra idéia...

Sub anacleto()
    ' Declaração de variáveis
    Call desprotegerGuia
    ' Meu código filtro
    Call protegerGuia
End Sub
Sub protegerGuia()
ActiveSheet.protect Password:="123", DrawingObjects:=True, _
contents:=True, Scenarios:=True, AllowFiltering:=True, userinterfaceonly:=True
End Sub
Sub desprotegerGuia()
ActiveSheet.Unprotect Password:="123", DrawingObjects:=True, _
contents:=True, Scenarios:=True, AllowFiltering:=True, userinterfaceonly:=True
End Sub

Att

 
Postado : 14/07/2017 9:29 am
(@anacletotranstusa)
Posts: 64
Estimable Member
Topic starter
 

Show! Muito obrigado!

 
Postado : 14/07/2017 11:25 am