PC Review


Reply
Thread Tools Rate Thread

How to activate a worksheet at a set time

 
 
Shatin
Guest
Posts: n/a
 
      17th Feb 2008
I have a file with several worksheets which need to be updated with data
from the web. I have already written a macro ("UpdateSheet") which can
achieve this task. This macro requires the name of the worksheet which calls
the macro to work properly.

I'd like to automate the task and have written a macro as below. The idea
is that one second before the scheduled update time, the proper worksheet
will first be activated (in case I am working on another worksheet or even
another workbook), and then the update will carried out:

------
Sub AutoUpdate()

Dim SheetName As String
Dim UpdateTime As Date

SheetName = ActiveSheet.Name
UpdateTime = Range("C38").Value

Application.OnTime TimeValue(UpdateTime - TimeValue("0:00:01")),
ThisWorkbook.Sheets(SheetName).Activate
Application.OnTime TimeValue(UpdateTime), "UpdateSheet"

End Sub
------

The problem is that the following line isn't working properly:

Application.OnTime TimeValue(UpdateTime - TimeValue("0:00:01")),
ThisWorkbook.Sheets(SheetName).Activate

At the scheduled time I get this error message from Excel:

The macro "<<filename.xls>>'!True' cannot be found -- <<filename.xls>> is
the full path filename. What I don't understand is why is Excel looking for
this mysterious True macro???

Incidentally, when I tried to debug.print at a set time, I get the same
error message.

Can somebody tell me what I have done wrong?

Thanks!



 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      17th Feb 2008
I'd try:

Sub AutoUpdate()

Dim SheetName As String
Dim UpdateTime As Date

SheetName = ActiveSheet.Name
UpdateTime = Range("C38").Value

Application.OnTime UpdateTime, "UpdateSheet"

End Sub

UpdateTime already looks like a time. It doesn't need TimeValue().

You may want to take a look at Chip Pearson's notes on .ontime:
http://www.cpearson.com/excel/OnTime.aspx

Shatin wrote:
>
> I have a file with several worksheets which need to be updated with data
> from the web. I have already written a macro ("UpdateSheet") which can
> achieve this task. This macro requires the name of the worksheet which calls
> the macro to work properly.
>
> I'd like to automate the task and have written a macro as below. The idea
> is that one second before the scheduled update time, the proper worksheet
> will first be activated (in case I am working on another worksheet or even
> another workbook), and then the update will carried out:
>
> ------
> Sub AutoUpdate()
>
> Dim SheetName As String
> Dim UpdateTime As Date
>
> SheetName = ActiveSheet.Name
> UpdateTime = Range("C38").Value
>
> Application.OnTime TimeValue(UpdateTime - TimeValue("0:00:01")),
> ThisWorkbook.Sheets(SheetName).Activate
> Application.OnTime TimeValue(UpdateTime), "UpdateSheet"
>
> End Sub
> ------
>
> The problem is that the following line isn't working properly:
>
> Application.OnTime TimeValue(UpdateTime - TimeValue("0:00:01")),
> ThisWorkbook.Sheets(SheetName).Activate
>
> At the scheduled time I get this error message from Excel:
>
> The macro "<<filename.xls>>'!True' cannot be found -- <<filename.xls>> is
> the full path filename. What I don't understand is why is Excel looking for
> this mysterious True macro???
>
> Incidentally, when I tried to debug.print at a set time, I get the same
> error message.
>
> Can somebody tell me what I have done wrong?
>
> Thanks!


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
trigger worksheet activate event in another worksheet Raj Microsoft Excel Programming 2 2nd Jun 2008 01:09 PM
How do I activate the first worksheet? =?Utf-8?B?TWVsdGFk?= Microsoft Excel Programming 4 24th Jul 2007 09:44 AM
Change Worksheet Button Caption on Worksheet.Activate =?Utf-8?B?TWlrZVp6?= Microsoft Excel Programming 1 7th Dec 2006 06:01 AM
Activate Previous worksheet after adding a new worksheet Chingangel@yahoo.com Microsoft Excel Programming 3 19th Oct 2005 01:01 AM
Worksheet.activate =?Utf-8?B?SmVmZg==?= Microsoft Excel Misc 1 14th Dec 2004 01:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:41 PM.