Need Help Error Proofing the following VBA Timer Code

speed88bump

New Member
Joined
Aug 9, 2013
Messages
29
The basic purpose of what I am doing is I have a Target workbook with cells linked to Source WB and when I update the source I want it to update the Target Automatically every minute. The Target WB also has a countdown timer in it and when it reaches zero it processes the update.
The Target WB has the codes in it and it is opened and viewed on a monitor from another PC. The Source WB is on my PC when I update it, the Macro on the Target updates which is great. However, I keep receiving random error messages that when fixed it will work for an hour or two and then another error pops up. (You know how frustrating this can be when you have the evil doubters on the wing ready to pounce when it doesn't work). All because they don't understand it. Anyway, sorry about that back to business. I am using Excel 2010 and here is the code.
ThisWorkbook Module Consist of:
Option Explicit

Sub Workbook_Open()
Dim StopTimer As Boolean
Call Update_Links
'Start the timer
Const Minutes = 1
Dim EndTime As Double
StopTimer = False
Do
If EndTime - Now < 0 Then
Call Update_Links
EndTime = Now + TimeSerial(0, Minutes, 0)
End If
ThisWorkbook.ActiveSheet.Range("B1") = EndTime - Now ***
DoEvents
Loop Until StopTimer

End Sub

Sub Workbook_Close()
Dim StopTimer As Boolean
StopTimer = True
End Sub

A separate Module contains:
Sub Update_Links()
On Error Resume Next
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
End Sub


Sub Workbook_Stop()
Dim StopTimer As Boolean
StopTimer = True
End Sub

The item with 3 asteriks next to it is where I receive most errors from.
ThisWorkbook.ActiveSheet.Range("B1") = EndTime - Now ***
Usually a compile error. Originally it was just Range("B1") then I changed it to ActiveSheet.Range("B1") after another error I changed it to Thisworkbook.ActiveSheet.Range(B1")
I have to use ActiveSheet because there are 7 worksheet tabs on the Target WB one for each day.
Range("B1") contains a count down timer. Update_Links well.... Updates the Links.
Is their a cleaner way of writting this to make it solid and not error out everytime someone looks at it funny.
FYI... The Target WB is the only open Excel WB on this monitor.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
maybe try
Code:
debug.print[/COLOR] [COLOR=#333333]EndTime - Now[/COLOR]
right before the issue in question and see what is happening to cause error.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top