Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Application Ontime

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Hood - 30 Aug 2005 06:53 GMT
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

Signature

Beyond Help And Reason

Edward Thrashcort - 30 Aug 2005 12:43 GMT
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

> 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.
[quoted text clipped - 23 lines]
> msgbox ("Nothing Open")
> End Sub
Chris Hood - 30 Aug 2005 19:26 GMT
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.  

Signature

Beyond Help And Reason

> Maybe you should use the correct formal syntax:
>
[quoted text clipped - 38 lines]
> > msgbox ("Nothing Open")
> > End Sub
Chris Hood - 30 Aug 2005 22:12 GMT
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?
Signature

Beyond Help And Reason

> Maybe you should use the correct formal syntax:
>
[quoted text clipped - 38 lines]
> > msgbox ("Nothing Open")
> > End Sub
Helmut Weber - 30 Aug 2005 16:40 GMT
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"

>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.
[quoted text clipped - 24 lines]
>msgbox ("Nothing Open")
>End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.