Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default How to activate a worksheet at a set time

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!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to activate a worksheet at a set time

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Time Error on activate coding Cammy Excel Programming 2 April 19th 07 12:02 PM
Change Worksheet Button Caption on Worksheet.Activate MikeZz Excel Programming 1 December 7th 06 06:01 AM
Activate Previous worksheet after adding a new worksheet [email protected] Excel Programming 3 October 19th 05 01:01 AM
Run-time error '1004' on Range.Activate Don Rouse Excel Programming 9 August 25th 05 04:05 PM
How to activate array formulas in a range of cells all at the same time? Karenna Excel Programming 3 February 29th 04 11:30 PM


All times are GMT +1. The time now is 07:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"