Run Error while protected

M

MAX

I have a code (below), that blinks certain cells in a workbook where it works
perfect, but when I protect the workbook it stops working and it is giving me
a (Run Time Error 1004).
Is there a solution for this?

Thanks a lot.

Workbook code:
Private Sub Workbook_Open()
StartBlink
StartBlink2
StartBlink3
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopBlink
StopBlink2
StopBlink3
End Sub

Module Code:

Public RunWhen As Double

Sub StartBlink()
With ThisWorkbook.Worksheets("Serie A").Range("AN6,AW6").Font
If .ColorIndex = 3 Then ' Red Text
.ColorIndex = 31 ' White Text
Else
.ColorIndex = 3 ' Red Text
End If
End With
RunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime RunWhen, "StartBlink", , True
End Sub

Sub StopBlink()
ThisWorkbook.Worksheets("Serie A").Range("AN6,AW6").Font.ColorIndex = _
xlColorIndexAutomatic
Application.OnTime RunWhen, "StartBlink", , False
End Sub


Sub StartBlink2()
With ThisWorkbook.Worksheets("Serie B").Range("AN6,AW6").Font
If .ColorIndex = 3 Then ' Red Text
.ColorIndex = 2 ' White Text
Else
.ColorIndex = 3 ' Red Text
End If
End With
RunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime RunWhen, "StartBlink2", , True
End Sub

Sub StopBlink2()
ThisWorkbook.Worksheets("Serie B").Range("AN6,AW6").Font.ColorIndex = _
xlColorIndexAutomatic
Application.OnTime RunWhen, "StartBlink2", , False
End Sub
Sub StartBlink3()
With ThisWorkbook.Worksheets("Serie C").Range("AN6,AW6,AN83,AW83").Font
If .ColorIndex = 3 Then ' Red Text
.ColorIndex = 2 ' White Text
Else
.ColorIndex = 3 ' Red Text
End If
End With
RunWhen = Now + TimeSerial(0, 0, 1)
Application.OnTime RunWhen, "StartBlink3", , True
End Sub

Sub StopBlink3()
ThisWorkbook.Worksheets("Serie
C").Range("AN6,AW6,AN83,AW83").Font.ColorIndex = _
xlColorIndexAutomatic
Application.OnTime RunWhen, "StartBlink3", , False
End Sub
 
M

Mike H

Max,

Do your protection at runtime and protect the userinterface only. As an
example you could do it in your workbook open event code

Private Sub Workbook_Open()
Sheets("serie A").Protect Password:="password", UserInterfaceOnly:=True
StartBlink
StartBlink2
StartBlink3
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Protection in VBA. 2
Run - time error '1004' 1
Code Error 3
Blinking cells 6
VBA code does not work 7
Code error 5
2 codes in one sheet 5
Flashing cells 5

Top