Notifications
Clear all

Corrigir erro 1004 em vba excel

6 Posts
2 Usuários
0 Reactions
1,229 Visualizações
(@fabioms82)
Posts: 0
New Member
Topic starter
 

Bom dia!

Criei uma planilha de fluxo de caixa, onde ativei a proteção através de senha em algumas células, ficando assim desabilitado o ícone onde formato a cor das fontes. Preciso dessas cores de fontes habilitadas para trabalhar em minha planilha. Para resolver a situação, criei 3 macros e inseri 3 botões para poder manusear a planilha trocando as cores das fontes, mas sem seguir nenhum critério específico. O problema é que ao utilizar os botões e fazer as alterações de cores, me da mensagem de erro 1004 e preciso de ajuda para corrigir o erro.
Segue abaixo o código criado em vba quando criei as macros:

Sub Previsto()
'
' Previsto Macro
' Valores previstos
'
' Atalho do teclado: Ctrl+Shift+P
'
With Selection.Font
.Color = -16776961
.TintAndShade = 0

End With
End Sub
Sub Agendado()
'
' Agendado Macro
' Valores agendados
'
' Atalho do teclado: Ctrl+Shift+G
'
With Selection.Font
.Color = -11489280
.TintAndShade = 0
End With
End Sub
Sub Realizado()
'
' Realizado Macro
' Valores realizados
'
' Atalho do teclado: Ctrl+Shift+R
'
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
End Sub

Poderiam me orientar de que forma consigo corrigir o erro?

 
Postado : 12/01/2015 8:45 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Eu posso está enganado, mas é provável que o erro é a proteção!

Você deve desproteger (manualmente ou via VBA), a guia e depois proteger novamente.
Para maiores detalhes veja:
http://www.google.com.br/cse?cx=partner ... gsc.page=1

Att

 
Postado : 12/01/2015 8:57 am
(@fabioms82)
Posts: 0
New Member
Topic starter
 

Boa tarde Alexandre!
Na verdade já tenho uma vba para proteger e desproteger a planilha e ela rodava perfeitamente. Com a inclusão dessas três novas macros para alteração de cor da fonte que apresentou o erro 1004.
Segue código de proteção:

Sub Macro()
Worksheets("ORÇAMENTO 2015").Unprotect "finprotege"
Worksheets("FC-REAL JAN").Unprotect "finprotege"
Worksheets("FC-REAL FEV").Unprotect "finprotege"
Worksheets("FC-REAL MAR").Unprotect "finprotege"
Worksheets("FC-REAL ABR").Unprotect "finprotege"
Worksheets("FC-REAL MAI").Unprotect "finprotege"
Worksheets("FC-REAL JUN").Unprotect "finprotege"
Worksheets("FC-REAL JUL").Unprotect "finprotege"
Worksheets("FC-REAL AGO").Unprotect "finprotege"
Worksheets("FC-REAL SET").Unprotect "finprotege"
Worksheets("FC-REAL OUT").Unprotect "finprotege"
Worksheets("FC-REAL NOV").Unprotect "finprotege"
Worksheets("FC-REAL DEZ").Unprotect "finprotege"
Worksheets("REALIZADO TOTAL").Unprotect "finprotege"
Worksheets("DR - JAN").Unprotect "finprotege"
Worksheets("DR - FEV").Unprotect "finprotege"
Worksheets("DR - MAR").Unprotect "finprotege"
Worksheets("DR - ABR").Unprotect "finprotege"
Worksheets("DR - MAI").Unprotect "finprotege"
Worksheets("DR - JUN").Unprotect "finprotege"
Worksheets("DR - JUL").Unprotect "finprotege"
Worksheets("DR - AGO").Unprotect "finprotege"
Worksheets("DR - SET").Unprotect "finprotege"
Worksheets("DR - OUT").Unprotect "finprotege"
Worksheets("DR - NOV").Unprotect "finprotege"
Worksheets("DR - DEZ").Unprotect "finprotege"
' Macro Macro
' Visão Macro
'
' Atalho do teclado: Ctrl+m
'
ActiveSheet.Outline.ShowLevels RowLevels:=1

Worksheets("ORÇAMENTO 2015").Protect "finprotege"
Worksheets("FC-REAL JAN").Protect "finprotege"
Worksheets("FC-REAL FEV").Protect "finprotege"
Worksheets("FC-REAL MAR").Protect "finprotege"
Worksheets("FC-REAL ABR").Protect "finprotege"
Worksheets("FC-REAL MAI").Protect "finprotege"
Worksheets("FC-REAL JUN").Protect "finprotege"
Worksheets("FC-REAL JUL").Protect "finprotege"
Worksheets("FC-REAL AGO").Protect "finprotege"
Worksheets("FC-REAL SET").Protect "finprotege"
Worksheets("FC-REAL OUT").Protect "finprotege"
Worksheets("FC-REAL NOV").Protect "finprotege"
Worksheets("FC-REAL DEZ").Protect "finprotege"
Worksheets("REALIZADO TOTAL").Protect "finprotege"
Worksheets("DR - JAN").Protect "finprotege"
Worksheets("DR - FEV").Protect "finprotege"
Worksheets("DR - MAR").Protect "finprotege"
Worksheets("DR - ABR").Protect "finprotege"
Worksheets("DR - MAI").Protect "finprotege"
Worksheets("DR - JUN").Protect "finprotege"
Worksheets("DR - JUL").Protect "finprotege"
Worksheets("DR - AGO").Protect "finprotege"
Worksheets("DR - SET").Protect "finprotege"
Worksheets("DR - OUT").Protect "finprotege"
Worksheets("DR - NOV").Protect "finprotege"
Worksheets("DR - DEZ").Protect "finprotege"

End Sub
Sub Sintético()

Worksheets("ORÇAMENTO 2015").Unprotect "finprotege"
Worksheets("FC-REAL JAN").Unprotect "finprotege"
Worksheets("FC-REAL FEV").Unprotect "finprotege"
Worksheets("FC-REAL MAR").Unprotect "finprotege"
Worksheets("FC-REAL ABR").Unprotect "finprotege"
Worksheets("FC-REAL MAI").Unprotect "finprotege"
Worksheets("FC-REAL JUN").Unprotect "finprotege"
Worksheets("FC-REAL JUL").Unprotect "finprotege"
Worksheets("FC-REAL AGO").Unprotect "finprotege"
Worksheets("FC-REAL SET").Unprotect "finprotege"
Worksheets("FC-REAL OUT").Unprotect "finprotege"
Worksheets("FC-REAL NOV").Unprotect "finprotege"
Worksheets("FC-REAL DEZ").Unprotect "finprotege"
Worksheets("REALIZADO TOTAL").Unprotect "finprotege"
Worksheets("DR - JAN").Unprotect "finprotege"
Worksheets("DR - FEV").Unprotect "finprotege"
Worksheets("DR - MAR").Unprotect "finprotege"
Worksheets("DR - ABR").Unprotect "finprotege"
Worksheets("DR - MAI").Unprotect "finprotege"
Worksheets("DR - JUN").Unprotect "finprotege"
Worksheets("DR - JUL").Unprotect "finprotege"
Worksheets("DR - AGO").Unprotect "finprotege"
Worksheets("DR - SET").Unprotect "finprotege"
Worksheets("DR - OUT").Unprotect "finprotege"
Worksheets("DR - NOV").Unprotect "finprotege"
Worksheets("DR - DEZ").Unprotect "finprotege"
' Sintético Macro
' Visão Sintética
'
' Atalho do teclado: Ctrl+s
'
ActiveSheet.Outline.ShowLevels RowLevels:=2

Worksheets("ORÇAMENTO 2015").Protect "finprotege"
Worksheets("FC-REAL JAN").Protect "finprotege"
Worksheets("FC-REAL FEV").Protect "finprotege"
Worksheets("FC-REAL MAR").Protect "finprotege"
Worksheets("FC-REAL ABR").Protect "finprotege"
Worksheets("FC-REAL MAI").Protect "finprotege"
Worksheets("FC-REAL JUN").Protect "finprotege"
Worksheets("FC-REAL JUL").Protect "finprotege"
Worksheets("FC-REAL AGO").Protect "finprotege"
Worksheets("FC-REAL SET").Protect "finprotege"
Worksheets("FC-REAL OUT").Protect "finprotege"
Worksheets("FC-REAL NOV").Protect "finprotege"
Worksheets("FC-REAL DEZ").Protect "finprotege"
Worksheets("REALIZADO TOTAL").Protect "finprotege"
Worksheets("DR - JAN").Protect "finprotege"
Worksheets("DR - FEV").Protect "finprotege"
Worksheets("DR - MAR").Protect "finprotege"
Worksheets("DR - ABR").Protect "finprotege"
Worksheets("DR - MAI").Protect "finprotege"
Worksheets("DR - JUN").Protect "finprotege"
Worksheets("DR - JUL").Protect "finprotege"
Worksheets("DR - AGO").Protect "finprotege"
Worksheets("DR - SET").Protect "finprotege"
Worksheets("DR - OUT").Protect "finprotege"
Worksheets("DR - NOV").Protect "finprotege"
Worksheets("DR - DEZ").Protect "finprotege"
End Sub
Sub Aberto()

Worksheets("ORÇAMENTO 2015").Unprotect "finprotege"
Worksheets("FC-REAL JAN").Unprotect "finprotege"
Worksheets("FC-REAL FEV").Unprotect "finprotege"
Worksheets("FC-REAL MAR").Unprotect "finprotege"
Worksheets("FC-REAL ABR").Unprotect "finprotege"
Worksheets("FC-REAL MAI").Unprotect "finprotege"
Worksheets("FC-REAL JUN").Unprotect "finprotege"
Worksheets("FC-REAL JUL").Unprotect "finprotege"
Worksheets("FC-REAL AGO").Unprotect "finprotege"
Worksheets("FC-REAL SET").Unprotect "finprotege"
Worksheets("FC-REAL OUT").Unprotect "finprotege"
Worksheets("FC-REAL NOV").Unprotect "finprotege"
Worksheets("FC-REAL DEZ").Unprotect "finprotege"
Worksheets("REALIZADO TOTAL").Unprotect "finprotege"
Worksheets("DR - JAN").Unprotect "finprotege"
Worksheets("DR - FEV").Unprotect "finprotege"
Worksheets("DR - MAR").Unprotect "finprotege"
Worksheets("DR - ABR").Unprotect "finprotege"
Worksheets("DR - MAI").Unprotect "finprotege"
Worksheets("DR - JUN").Unprotect "finprotege"
Worksheets("DR - JUL").Unprotect "finprotege"
Worksheets("DR - AGO").Unprotect "finprotege"
Worksheets("DR - SET").Unprotect "finprotege"
Worksheets("DR - OUT").Unprotect "finprotege"
Worksheets("DR - NOV").Unprotect "finprotege"
Worksheets("DR - DEZ").Unprotect "finprotege"
' Aberto Macro
' Visão Aberta
'
' Atalho do teclado: Ctrl+a
'
ActiveSheet.Outline.ShowLevels RowLevels:=3

Worksheets("ORÇAMENTO 2015").Protect "finprotege"
Worksheets("FC-REAL JAN").Protect "finprotege"
Worksheets("FC-REAL FEV").Protect "finprotege"
Worksheets("FC-REAL MAR").Protect "finprotege"
Worksheets("FC-REAL ABR").Protect "finprotege"
Worksheets("FC-REAL MAI").Protect "finprotege"
Worksheets("FC-REAL JUN").Protect "finprotege"
Worksheets("FC-REAL JUL").Protect "finprotege"
Worksheets("FC-REAL AGO").Protect "finprotege"
Worksheets("FC-REAL SET").Protect "finprotege"
Worksheets("FC-REAL OUT").Protect "finprotege"
Worksheets("FC-REAL NOV").Protect "finprotege"
Worksheets("FC-REAL DEZ").Protect "finprotege"
Worksheets("REALIZADO TOTAL").Protect "finprotege"
Worksheets("DR - JAN").Protect "finprotege"
Worksheets("DR - FEV").Protect "finprotege"
Worksheets("DR - MAR").Protect "finprotege"
Worksheets("DR - ABR").Protect "finprotege"
Worksheets("DR - MAI").Protect "finprotege"
Worksheets("DR - JUN").Protect "finprotege"
Worksheets("DR - JUL").Protect "finprotege"
Worksheets("DR - AGO").Protect "finprotege"
Worksheets("DR - SET").Protect "finprotege"
Worksheets("DR - OUT").Protect "finprotege"
Worksheets("DR - NOV").Protect "finprotege"
Worksheets("DR - DEZ").Protect "finprotege"
End Sub

 
Postado : 12/01/2015 10:18 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Por gentileza, há como postar seu arquivo cujo você relata o erro?

Att

 
Postado : 12/01/2015 11:04 am
(@fabioms82)
Posts: 0
New Member
Topic starter
 

Boa tarde Alexandre!

Consegui solucionar o erro. De fato era necessário desativar a proteção, rodar a macro e ativar a proteção novamente em seguida.
As novas macros ficaram então com os seguintes códigos:

Sub Previsto()
'
' Previsto Macro
' Valores previstos
'
' Atalho do teclado: Ctrl+Shift+P
'
pUnprotect
With Selection.Font
.Color = -16776961
.TintAndShade = 0

End With
pProtect
End Sub
Sub Agendado()
'
' Agendado Macro
' Valores agendados
'
' Atalho do teclado: Ctrl+Shift+G
'
pUnprotect
With Selection.Font
.Color = -11489280
.TintAndShade = 0
End With
pProtect
End Sub
Sub Realizado()
'
' Realizado Macro
' Valores realizados
'
' Atalho do teclado: Ctrl+Shift+R
'
pUnprotect
With Selection.Font
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
pProtect
End Sub

Private Sub pProtect()
ActiveSheet.Protect "senha de proteção"
End Sub

Private Sub pUnprotect()
ActiveSheet.Unprotect "senha de proteção"
End Sub

Obrigado pela ajuda!!!

 
Postado : 14/01/2015 12:05 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!

Eu fico feliz que resolveu, obrigado pelo retorno!!

Se a dica foi útil, click na mãozinha

Att

 
Postado : 14/01/2015 1:03 pm