VBA code does not work

  • Thread starter Frank Situmorang
  • Start date
F

Frank Situmorang

Hello,

I have inserted these VBA in the module, but the text in T2 does not blink.
Did I miss something?

Public RunWhen As Double

Sub StartBlink()
With ThisWorkbook.Worksheets("PO_Line_text").Range("T2").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, "'" & ThisWorkbook.Name & "'!StartBlink", ,
True
End Sub

Sub StopBlink()
ThisWorkbook.Worksheets("PO_Line_text").Range("T2").Font.ColorIndex = _
xlColorIndexAutomatic
Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink", ,
False
End Sub

'Then, in the ThisWorkbook code module of the workbook, use code like:

Private Sub Workbook_Open()
StartBlink
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopBlink
End Sub
 
B

Bob Phillips

Works fine for me Frank. Did you put the workbook event procedures in
ThisWorkbook?
 
F

Frank Situmorang

No I didn't Phillip, I do not even know where is workbook event procedures .

Could you tell me?
 
B

Bob Phillips

Near the bottom of the code that you posted you will read


'Then, in the ThisWorkbook code module of the workbook, use code like:


Each VBA project consists of various objects, worksheets, modules and
ThisWorkbook. Copy that code to there.
 
F

Frank Situmorang

I already copied that Phil, exactly like the VBA I mentioned. Maybe somthing
I missed.
Application.OnTime RunWhen, "'" & ThisWorkbook.Name

Waht is this: "'" , should it be filled in the middle?
 
M

Mike H

The code requires no alterations, it's correct. If your confident you've put
all the code where it should be, did you save, close and re-open the workbook?

Mike
 
F

Frank Situmorang

This is exactly what I copied Mike, and I saved and opened it, but it is
still not blinking. I am using excel2007. So while open my workbook. I go to
toolbar developer than clicked VBA code, then I copied, saved and reopend
still nothing happend

Public RunWhen As Double

Sub StartBlink()
With ThisWorkbook.Worksheets("PO_Line_text").Range("T2").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, "'" & ThisWorkbook.Name & "'!StartBlink", ,
True
End Sub

Sub StopBlink()
ThisWorkbook.Worksheets("PO_Line_text").Range("T2").Font.ColorIndex = _
xlColorIndexAutomatic
Application.OnTime RunWhen, "'" & ThisWorkbook.Name & "'!StartBlink", ,
False
End Sub

'Then, in the ThisWorkbook code module of the workbook, use code like:

Private Sub Workbook_Open()
StartBlink
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopBlink
End Sub
 
F

Frank Situmorang

Thanks to all of you, it works now for me, the 2nd part should have been
copied to the proper place.
 

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

Blinking cells 6
Run Error while protected 1
Protection in VBA. 2
Code Error 3
Run - time error '1004' 1
2 codes in one sheet 5
Simple Variable to someone 5
Two codes in one set. 1

Top