Discussion:
Application Ontime
(too old to reply)
Chris Hood
2005-08-30 05:53:02 UTC
Permalink
Ok i have read every post in in the newsgroups and i am still lost. I have
this code in my global template in word.

It does not function at all. I do not see it run anything at all. If i set
it 5 minutes ahead and site and wait it does nothing. If i change it to code
2 listed below. It runs at the correct time but then also runs every time
word is opened once that time has passed.
Can someone test this code and tell me if it is just me or is it word that
is brooken.

Code 1
Sub AutoExec()
Application.OnTime TimeValue("19:36:00"),"KSG.Module1.Testing1"
End Sub

Sub Testing1()
msgbox ("Nothing Open")
End Sub


Code 2

Sub AutoExec()
Application.OnTime "19:36:00", "KSG.Module1.Testing1"
End Sub

Sub Testing1()
msgbox ("Nothing Open")
End Sub
--
Beyond Help And Reason
Edward Thrashcort
2005-08-30 11:43:00 UTC
Permalink
Maybe you should use the correct formal syntax:

eg
Application.OnTime _
When:="19:36:00", _
Name:="KSG.Module1.Testing1" _
Tolerance:=TimeValue("00:30:00")

should run the macro at 19:36:00 or for half an hour after that time if the
system is busy.

Each time you open Word between 19:36 and 20:06 the macro should run

Eddie
Post by Chris Hood
Ok i have read every post in in the newsgroups and i am still lost. I
have this code in my global template in word.
It does not function at all. I do not see it run anything at all. If i
set it 5 minutes ahead and site and wait it does nothing. If i change it
to code 2 listed below. It runs at the correct time but then also runs
every time word is opened once that time has passed. Can someone test
this code and tell me if it is just me or is it word that is brooken.
Code 1
Sub AutoExec()
Application.OnTime TimeValue("19:36:00"),"KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
Code 2
Sub AutoExec()
Application.OnTime "19:36:00", "KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
--
Beyond Help And Reason
Chris Hood
2005-08-30 18:26:47 UTC
Permalink
I will format the statment correctly. And try again.

So with this sub it will run a script betwen thouse times as long as word is
open. Reason i ask. True problem need resolving. I need to have it that
if any document is open at 3:00 am to have them saved to the desktop so i can
forces hutdown all work sations.
--
Beyond Help And Reason
Post by Edward Thrashcort
eg
Application.OnTime _
When:="19:36:00", _
Name:="KSG.Module1.Testing1" _
Tolerance:=TimeValue("00:30:00")
should run the macro at 19:36:00 or for half an hour after that time if the
system is busy.
Each time you open Word between 19:36 and 20:06 the macro should run
Eddie
Post by Chris Hood
Ok i have read every post in in the newsgroups and i am still lost. I
have this code in my global template in word.
It does not function at all. I do not see it run anything at all. If i
set it 5 minutes ahead and site and wait it does nothing. If i change it
to code 2 listed below. It runs at the correct time but then also runs
every time word is opened once that time has passed. Can someone test
this code and tell me if it is just me or is it word that is brooken.
Code 1
Sub AutoExec()
Application.OnTime TimeValue("19:36:00"),"KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
Code 2
Sub AutoExec()
Application.OnTime "19:36:00", "KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
--
Beyond Help And Reason
Chris Hood
2005-08-30 21:12:02 UTC
Permalink
Nice try. I put in exeactly as you have it. And if the time is past the
time then it works fine. But if i set it to 8:00 am and have the tol at 1
minute it runs everytime word is open untill i set the system clock to before
8:00am then it will wait.

Do i maybe need to add a date in there as well so if it is after the time i
want to save have it set to the next day at that time?

If so how would i do that?
--
Beyond Help And Reason
Post by Edward Thrashcort
eg
Application.OnTime _
When:="19:36:00", _
Name:="KSG.Module1.Testing1" _
Tolerance:=TimeValue("00:30:00")
should run the macro at 19:36:00 or for half an hour after that time if the
system is busy.
Each time you open Word between 19:36 and 20:06 the macro should run
Eddie
Post by Chris Hood
Ok i have read every post in in the newsgroups and i am still lost. I
have this code in my global template in word.
It does not function at all. I do not see it run anything at all. If i
set it 5 minutes ahead and site and wait it does nothing. If i change it
to code 2 listed below. It runs at the correct time but then also runs
every time word is opened once that time has passed. Can someone test
this code and tell me if it is just me or is it word that is brooken.
Code 1
Sub AutoExec()
Application.OnTime TimeValue("19:36:00"),"KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
Code 2
Sub AutoExec()
Application.OnTime "19:36:00", "KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
--
Beyond Help And Reason
Helmut Weber
2005-08-30 15:40:41 UTC
Permalink
Hi Chris,

I was playing around with this all day. Nothing worked.
Seems nobody here had a really good idea.

I then removed the ever desastrous Adobe "PDFMaker.dot".
With PDFMaker present, my autoexec wouldn't executed at all.
No wonder, as there is probably an autoexec in PDFMaker.

Still no success.

I remembered, that

Application.OnTime _
When:=Now + TimeValue(...)...

most often worked. Not to say always.
But life is a long song.

So I arrived at that:

Sub AutoExec()
Dim strTm1 As String ' a string representing a time
Dim strTm2 As String ' a string representing a time
Dim lngScs As Long ' seconds

strTm1 = "17:35:00" ' start makro at this time
' get the number of seconds from now til then
lngScs = DateDiff("s", Time, strTm1) ' seconds

strTm2 = TimeString(lngScs)

Application.OnTime _
When:=Now + TimeValue(TimeString(lngScs)), _
Name:="NewMacros.Test5431"
End Sub
' ---
Public Function TimeString(ByVal Secs As Long) As String
Dim hh As Long
Dim mm As Long
Dim ss As Long
hh = Secs - Secs Mod 3600
hh = hh / 3600
Secs = Secs - hh * 3600
mm = Secs - Secs Mod 60
mm = mm / 60
Secs = Secs - mm * 60
ss = Secs
TimeString = Format(hh, "00") & ":"
TimeString = TimeString & Format(mm, "00")
TimeString = TimeString & ":" & Format(ss, "00")
End Function

There must be more clever ways of building
a string representing a time from a number of seconds
(from midnight). But before searching for a day
for a ready to use function, I'd rather do it myself.

HTH

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Post by Chris Hood
Ok i have read every post in in the newsgroups and i am still lost. I have
this code in my global template in word.
It does not function at all. I do not see it run anything at all. If i set
it 5 minutes ahead and site and wait it does nothing. If i change it to code
2 listed below. It runs at the correct time but then also runs every time
word is opened once that time has passed.
Can someone test this code and tell me if it is just me or is it word that
is brooken.
Code 1
Sub AutoExec()
Application.OnTime TimeValue("19:36:00"),"KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
Code 2
Sub AutoExec()
Application.OnTime "19:36:00", "KSG.Module1.Testing1"
End Sub
Sub Testing1()
msgbox ("Nothing Open")
End Sub
Continue reading on narkive:
Loading...