PDA

View Full Version : [SOLVED:] Application.OnTime with arguments (totally stumped)



gmaxey
10-03-2013, 09:50 AM
I am trying to call a procedure that take arguments using Application.OnTime.

I'm almost positive that I've had success with this before, but now I simply can't get it to work. I'm trying to use the syntax outlined here: http://www.markrowlinson.co.uk/articles.php?id=10

In a standard module I have this code to run tests. Tests 1-3 run fine (the called procedures don't take arguments). However, with Test 4-5 nothing happens.

I'm sitting here surrounded with piles of hair and bloody scalp! What am I missing/doing wrong? Thanks

Option Explicit
Sub Test1()
Application.OnTime When:=Now + 0.000005, Name:="Testing1"
End Sub
Sub Test2()
Application.OnTime When:=Now + 0.000005, Name:="modMain.Testing2"
End Sub
Sub Test3()
Application.OnTime When:=Now + 0.000005, Name:="Project.modMain.Testing3"
End Sub
Sub Test4()
Application.OnTime When:=Now + 0.000005, Name:="'Testing4 ""Test 4""'"
End Sub
Sub Test5()
Application.OnTime When:=Now + 0.000005, Name:="'modMain.Testing4 ""Test 4""'"
End Sub
Sub Test6()
Application.OnTime When:=Now + 0.000005, Name:="'Project.modMain.Testing4 ""Test 4""'"
End Sub


In another standard module named modMain, I have these procedures:



Option Explicit
Sub Testing1()
MsgBox "Test 1"
End Sub
Sub Testing2()
MsgBox "Test 2"
End Sub
Sub Testing3()
MsgBox "Test 3"
End Sub
Sub Testing4(strTest As String)
MsgBox strTest
End Sub

Dave
10-03-2013, 10:27 AM
Have you resolved this yet? This works for me...

Application.OnTime Now + TimeValue("00:00:01"), "'testing4 ""BART""'"

This must be in Module code...

Sub Testing4(strTest As String)
MsgBox strTest
End Sub
HTH. Dave

gmaxey
10-03-2013, 10:55 AM
Dave,

No I haven't.

I copied and pasted your code in the ThisDocument Module and then tried again using a Standard Module in Word 2003, 2007, 2010 and 2013 and also in Word 2010 starting with winword /a and in each case nothing happens when I run the code. I'm just completely stumped!


Sub Test()
Application.OnTime Now + TimeValue("00:00:01"), "'testing4 ""BART""'"
End Sub
Sub testing4(pstr As String)
MsgBox pstr
End Sub

Dave
10-03-2013, 11:05 AM
My apologies. I forgot what forum I was in. That code worked for XL. I'll give it a go in Word. Dave

macropod
10-03-2013, 03:53 PM
Hi Greg,

Let's start with the basics - does this work for you:

Sub Demo()
MsgBox Now()
Application.OnTime Now() + TimeValue("00:00:05"), "Demo"
End Sub

gmaxey
10-03-2013, 04:16 PM
Paul. Yes it works.

So does this:



Sub Demo()
MsgBox Now()
Application.OnTime Now() + 0.00005, "Demo"
End Sub


Both work similar to the first three tests in my posted code works.

Thanks.

macropod
10-03-2013, 05:37 PM
Hi Greg,

I missed the part from your original post re passing arguments. Word's OnTime method doesn't support them. Instead, it has a 'tolerance' parameter to accommodate other timing issues.

gmaxey
10-03-2013, 06:06 PM
Paul,

No problem. At least I know that I was wrong to think I had done it before and can stop trying to pound a square peg in a round hole.

This will work for my purposes:


Sub Test1()
Application.OnTime When:=Now + 0.000005, Name:="modMain.Test"
End Sub
Sub Test()
TestWithParameters "Test 1 string passed"
End Sub
Sub TestWithParameters(ByRef strPassed As String)
MsgBox strPassed
End Sub