From: AutoMagic on
I have created the following VBS code:

MyTest
Set objExcel = CreateObject("Excel.Application")
MsgBox "Before OnTime"
objExcel.Application.OnTime Now + TimeValue("00:00:05"), "MyTest"
MsgBox "After OnTime"

Sub MyTest()
MsgBox "MyTest"
End Sub

The first thing I see is "MyTest", verifies Sub MyTest() is working.
Then I see "Before OnTime"
Then I see "After OnTime"

I wait 5 seconds expecting to see "MyTest" again but nothing happens.
Not able to figure out what's happening since I am not getting any
errors. Any help would be appreciated.
From: "Dave "Crash" Dummy" on
> The first thing I see is "MyTest", verifies Sub MyTest() is working.
> Then I see "Before OnTime" Then I see "After OnTime"
>
> I wait 5 seconds expecting to see "MyTest" again but nothing happens.
> Not able to figure out what's happening since I am not getting any
> errors. Any help would be appreciated.

I can't run it because I don't have Excel, but what exactly are you
trying to do? Do you want "mytest()" to run once after a delay, or
do you want it to run every five seconds?

--
Crash

"Any sufficiently advanced technology is indistinguishable from magic."
~ Arthur C. Clarke ~
From: Csaba Gabor on
On Nov 25, 12:56 am, AutoMagic <handyman1...(a)gmail.com> wrote:
> I have created the following VBS code:
>
> MyTest
> Set objExcel = CreateObject("Excel.Application")
> MsgBox "Before OnTime"
> objExcel.Application.OnTime Now + TimeValue("00:00:05"), "MyTest"
> MsgBox "After OnTime"
>
> Sub MyTest()
>   MsgBox "MyTest"
> End Sub
>
> The first thing I see is "MyTest", verifies Sub MyTest() is working.
> Then I see "Before OnTime"
> Then I see "After OnTime"
>
> I wait 5 seconds expecting to see "MyTest" again but nothing happens.
> Not able  to figure out what's happening since I am not getting any
> errors.  Any help would be appreciated.

You have two sources of error. The following revision
illustrates them. The first is due to the fact that you
exit your program before Excel has a chance to do
anything. When you exit the VBScript program, the
Excel directive goes away, too. So sorry. You have
to specifically insist that Excel not go away just yet
by ensuring that your program not away as the below
shows.

Now you can finally see Excel make the call. And
Excel is deeply unhappy (but at least you get an
error message letting you know that Excel is trying
to make the call). Why does it die? Excel is trying
to make a call to routines that it knows about. Why
should it know about the routine in your VBScript?
I'd be curious to know whether there is a pure
VBScript mechanism to bypass this.

Csaba Gabor from Vienna

MyTest
Set objExcel = CreateObject("Excel.Application")
MsgBox "Before OnTime"
objExcel.Application.OnTime Now + _
TimeValue("00:00:05"), "MyTest"

Dim Till: Till = Now + TimeValue("00:00:10")

While Now < Till
wscript.sleep 1000
Wend

MsgBox "Script terminating"

Sub MyTest()
MsgBox "Hi mom"
End Sub
From: AutoMagic on
On Nov 24, 4:55 pm, "Dave \"Crash\" Dummy" <dva...(a)deathstar.mil>
wrote:
> > The first thing I see is "MyTest", verifies Sub MyTest() is working.
> >  Then I see "Before OnTime" Then I see "After OnTime"
>
> > I wait 5 seconds expecting to see "MyTest" again but nothing happens.
> >  Not able  to figure out what's happening since I am not getting any
> >  errors.  Any help would be appreciated.
>
> I can't run it because I don't have Excel, but what exactly are you
> trying to do? Do you want "mytest()" to run once after a delay, or
> do you want it to run every five seconds?
>
> --
> Crash
>
> "Any sufficiently advanced technology is indistinguishable from magic."
> ~ Arthur C. Clarke ~

What I'm trying to do is open, then close, an Excel file once a day by
using VBScript. The Excel file has email notifications that trigger
based on dates on the spreadsheet. Application OnTime works OK in
Excel VBA but can't get it to run in VBS. The reason I'm not using
the Excel file with the dates is because several people use that file
during the day. I could use a separate Excel to to do what I want but
I like using VBS because it's hidden while it runs. Also I am
restricted from using Windows Scheduler or any other scheduling
program at the site I'm at.
From: AutoMagic on
On Nov 24, 5:22 pm, Csaba Gabor <dans...(a)gmail.com> wrote:
> On Nov 25, 12:56 am, AutoMagic <handyman1...(a)gmail.com> wrote:
>
>
>
>
>
> > I have created the following VBS code:
>
> > MyTest
> > Set objExcel = CreateObject("Excel.Application")
> > MsgBox "Before OnTime"
> > objExcel.Application.OnTime Now + TimeValue("00:00:05"), "MyTest"
> > MsgBox "After OnTime"
>
> > Sub MyTest()
> >   MsgBox "MyTest"
> > End Sub
>
> > The first thing I see is "MyTest", verifies Sub MyTest() is working.
> > Then I see "Before OnTime"
> > Then I see "After OnTime"
>
> > I wait 5 seconds expecting to see "MyTest" again but nothing happens.
> > Not able  to figure out what's happening since I am not getting any
> > errors.  Any help would be appreciated.
>
> You have two sources of error.  The following revision
> illustrates them.  The first is due to the fact that you
> exit your program before Excel has a chance to do
> anything.  When you exit the VBScript program, the
> Excel directive goes away, too.  So sorry.  You have
> to specifically insist that Excel not go away just yet
> by ensuring that your program not away as the below
> shows.
>
> Now you can finally see Excel make the call.  And
> Excel is deeply unhappy (but at least you get an
> error message letting you know that Excel is trying
> to make the call).  Why does it die?  Excel is trying
> to make a call to routines that it knows about. Why
> should it know about the routine in your VBScript?
> I'd be curious to know whether there is a pure
> VBScript mechanism to bypass this.
>
> Csaba Gabor from Vienna
>
> MyTest
> Set objExcel = CreateObject("Excel.Application")
> MsgBox "Before OnTime"
> objExcel.Application.OnTime Now + _
>       TimeValue("00:00:05"), "MyTest"
>
> Dim Till: Till = Now + TimeValue("00:00:10")
>
> While Now < Till
>   wscript.sleep 1000
> Wend
>
> MsgBox "Script terminating"
>
> Sub MyTest()
>   MsgBox "Hi mom"
> End Sub- Hide quoted text -
>
> - Show quoted text -

Thanks. I may just use a separate (see note above) Excel file to do
what I want.