ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run Error while protected (https://www.excelbanter.com/excel-programming/427893-run-error-while-protected.html)

Max

Run Error while protected
 
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


Mike H

Run Error while protected
 
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

"MAX" wrote:

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



All times are GMT +1. The time now is 04:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com