Hello everyone,
I have a workbook I use to keep statistics (Excel 2007, attached) that I'm continually tinkering with and trying to improve (so you may have seen it before). Clicking each button adds one to a specific cell pertaining to the desk transaction type for a particular hour. The workbook sits open on the desktop at all times, and work fine as long as it's the only workbook open. However, if a user wishes to work on a different Excel workbook, it and my Tallybot will bang heads.
I know where the problem is springing from: I added a module that checks the time once a minute, and updates a cell to display the correct time, then saves itself. It's a feature I'd like to keep, because it reduces confusion as to when data (a copy of the "Results Sheet" worksheet) has last been saved to a shared drive, and whether or not to save the master file to the hard drive at the end of the day. The code in the problem module is:
Sub TimeUpdate()
dTime = Now + TimeValue("00:01:00")
Application.OnTime dTime, "TimeUpdate"
'Checks for current time every minute.
Workbooks("Tallybot Demonstrator.xlsm").Sheets("input sheet").Select
Range("a3") = Format(Now(), "h:mm AM/PM")
'Displays updated current time in cell a3 of Input Sheet.
Workbooks("Tallybot Demonstrator.xlsm").Save
End Sub
As I said, it works fine if it's the only workbook open, but when any other workbook is open, once the update minute rolls around, I get "Run-time error '1004': Select method of worksheet class failed." When I click debug, the problem line is:
Workbooks("Tallybot Demonstrator.xlsm").Sheets("input sheet").Select
I've tried a couple of other commands in place of that line, and the closest I've come to success was:
Workbooks("Tallybot Demonstrator.xlsm").Activate
Sheets("input sheet").Select
The problem there being if you're working in the other workbook you're forced over to the Tallybot and left there.
Is there a command that will tell the VBA module to run the TimeUpdate subroutine only on the Tallybot workbook, and to leave any other open Excel file alone?
Thanks so much,
-Hester's Dad
Bookmarks