Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Syntax for Application.Ontime incl Variable Parameter

Hi



I have sub below, which calls another proc after it finishes (it seemed to
error otherwise).



Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

...

...



dTimeDefault = Now() + TimeValue("00:00:05")

Application.OnTime dTimeDefault, "CreateNewWorksheet"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Syntax for Application.Ontime incl Variable Parameter

I always forget the syntax so I keep the following handy (some gleaned from
this ng, others I worked out myslf). Here's the complete set, numbers and
strings as values and variables -

Sub test()
Dim nVar1 As Long, nVar2 As Long
Dim sVar1 As String, sVar2 As String
Dim sMacro As String

' these four Ontimes will run in order from last to first

'''' number values
sMacro = " 'MacroNum ""123"" , ""789"" ' "

Application.OnTime Now, sMacro


'''' number variables
nVar1 = 1111: nVar2 = 2222
sMacro = " 'MacroNum " & nVar1 & " , " & nVar2 & " ' "

Application.OnTime Now, sMacro


'''' string values
sMacro = " 'MacroStr ""Prompt value1"", ""Title value2"" ' "

Application.OnTime Now, sMacro


'''' string variables
sVar1 = "Prompt var1": sVar2 = "Title var2"
sMacro = " 'MacroStr " & Chr(34) & sVar1 & Chr(34) & _
", " & Chr(34) & sVar2 & Chr(34) & " ' "

Application.OnTime Now, sMacro

End Sub

Sub MacroStr(s1 As String, s2 As String)
MsgBox s1, , s2
End Sub

Sub MacroNum(n1 As Long, n2 As Long)
MsgBox n1, , n2
End Sub

Regards,
Peter T


"Tim Childs" wrote in message
...
Hi



I have sub below, which calls another proc after it finishes (it seemed to
error otherwise).



Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

..

..



dTimeDefault = Now() + TimeValue("00:00:05")

Application.OnTime dTimeDefault, "CreateNewWorksheet"

.

.



End Sub





I now want to add a parameter to the CreateNewWorksheet procedure call

(and
the proc itself) i.e. something like:



Application.OnTime dTimeDefault, "CreateNewWorksheet(" & Wb & ")"



But it errors!



Please can you help with the syntax?



THANKS



Tim



PS Have searched on Google and John Green kindly helped previously (2002)
but it was for a fixed parameter rather than a variable (anyway I am stuck
now!):


http://groups.google.com/group/micro...ing/browse_thr

ead/thread/c5a0ba87b7bc254f/b9bb97043d13dd44?lnk=st&q=Application.Ontime+Par
ameter&rnum=3&hl=en#b9bb97043d13dd44




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Syntax for Application.Ontime incl Variable Parameter

Hi Peter

thanks v much.

I will try this out

Tim

"Peter T" <peter_t@discussions wrote in message
...
I always forget the syntax so I keep the following handy (some gleaned

from
this ng, others I worked out myslf). Here's the complete set, numbers and
strings as values and variables -

Sub test()
Dim nVar1 As Long, nVar2 As Long
Dim sVar1 As String, sVar2 As String
Dim sMacro As String

' these four Ontimes will run in order from last to first

'''' number values
sMacro = " 'MacroNum ""123"" , ""789"" ' "

Application.OnTime Now, sMacro


'''' number variables
nVar1 = 1111: nVar2 = 2222
sMacro = " 'MacroNum " & nVar1 & " , " & nVar2 & " ' "

Application.OnTime Now, sMacro


'''' string values
sMacro = " 'MacroStr ""Prompt value1"", ""Title value2"" ' "

Application.OnTime Now, sMacro


'''' string variables
sVar1 = "Prompt var1": sVar2 = "Title var2"
sMacro = " 'MacroStr " & Chr(34) & sVar1 & Chr(34) & _
", " & Chr(34) & sVar2 & Chr(34) & " ' "

Application.OnTime Now, sMacro

End Sub

Sub MacroStr(s1 As String, s2 As String)
MsgBox s1, , s2
End Sub

Sub MacroNum(n1 As Long, n2 As Long)
MsgBox n1, , n2
End Sub

Regards,
Peter T


"Tim Childs" wrote in message
...
Hi



I have sub below, which calls another proc after it finishes (it seemed

to
error otherwise).



Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

..

..



dTimeDefault = Now() + TimeValue("00:00:05")

Application.OnTime dTimeDefault, "CreateNewWorksheet"

.

.



End Sub





I now want to add a parameter to the CreateNewWorksheet procedure call

(and
the proc itself) i.e. something like:



Application.OnTime dTimeDefault, "CreateNewWorksheet(" & Wb & ")"



But it errors!



Please can you help with the syntax?



THANKS



Tim



PS Have searched on Google and John Green kindly helped previously

(2002)
but it was for a fixed parameter rather than a variable (anyway I am

stuck
now!):



http://groups.google.com/group/micro...ing/browse_thr


ead/thread/c5a0ba87b7bc254f/b9bb97043d13dd44?lnk=st&q=Application.Ontime+Par
ameter&rnum=3&hl=en#b9bb97043d13dd44






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Syntax for Application.Ontime incl Variable Parameter

You cannot pass an object as an argument with the method John (Green)
demonstrated. How to use a variable is something Peter has already shown
you.

You can always use a global variable to pass an object to a OnTime procedure
-- provided you can guarantee that that object variable will remain
untouched, and in your case I believe that will indeed be true.

So, in a standard module:

public aWB as workbook

sub CreateNewWorksheet ()
'aWB is now accessible from here
end sub

In the class module where you have the application variable:

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
dTimeDefault = Now() + TimeValue("00:00:05")
set aWB=Wb
Application.OnTime dTimeDefault, "CreateNewWorksheet"
End Sub

Also, if you are using this technique to defer execution of some code
because of problems doing so in the WorkbookOpen procedure, you should be
able to use just Now() rather than impose a 5 second delay. It's a "trick"
I, myself, have used on more than a few occasions. Essentially,

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
set aWB=Wb
Application.OnTime Now(), "CreateNewWorksheet"
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hi



I have sub below, which calls another proc after it finishes (it seemed to
error otherwise).



Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

..

..



dTimeDefault = Now() + TimeValue("00:00:05")

Application.OnTime dTimeDefault, "CreateNewWorksheet"

.

.



End Sub





I now want to add a parameter to the CreateNewWorksheet procedure call (and
the proc itself) i.e. something like:



Application.OnTime dTimeDefault, "CreateNewWorksheet(" & Wb & ")"



But it errors!



Please can you help with the syntax?



THANKS



Tim



PS Have searched on Google and John Green kindly helped previously (2002)
but it was for a fixed parameter rather than a variable (anyway I am stuck
now!):

http://groups.google.com/group/micro...ing/browse_thr
ead/thread/c5a0ba87b7bc254f/b9bb97043d13dd44?lnk=st&q=Application.Ontime+Par
ameter&rnum=3&hl=en#b9bb97043d13dd44



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Syntax for Application.Ontime incl Variable Parameter

Hi Tushar,

Yes I should have mentioned it's not possible to pass an object OnTime,
especially as the OP had named the variable 'Wb'. I suppose as an
alternative to setting a global object reference it would be possible to
pass the workbook's string name and then set a new reference in the called
macro. I wasn't sure what the OP was doing.

I also use OnTime in the open event of some addins to do things that are
only possible once there is an activeworkbook, eg certain application level
settings. Like you I use 'Now' as it will only be called after everything
else has loaded, including any workbooks primed to load.

Regards,
Peter T


"Tushar Mehta" wrote in message
m...
You cannot pass an object as an argument with the method John (Green)
demonstrated. How to use a variable is something Peter has already shown
you.

You can always use a global variable to pass an object to a OnTime

procedure
-- provided you can guarantee that that object variable will remain
untouched, and in your case I believe that will indeed be true.

So, in a standard module:

public aWB as workbook

sub CreateNewWorksheet ()
'aWB is now accessible from here
end sub

In the class module where you have the application variable:

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
dTimeDefault = Now() + TimeValue("00:00:05")
set aWB=Wb
Application.OnTime dTimeDefault, "CreateNewWorksheet"
End Sub

Also, if you are using this technique to defer execution of some code
because of problems doing so in the WorkbookOpen procedure, you should be
able to use just Now() rather than impose a 5 second delay. It's a

"trick"
I, myself, have used on more than a few occasions. Essentially,

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
set aWB=Wb
Application.OnTime Now(), "CreateNewWorksheet"
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hi



I have sub below, which calls another proc after it finishes (it seemed

to
error otherwise).



Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

..

..



dTimeDefault = Now() + TimeValue("00:00:05")

Application.OnTime dTimeDefault, "CreateNewWorksheet"

.

.



End Sub





I now want to add a parameter to the CreateNewWorksheet procedure call

(and
the proc itself) i.e. something like:



Application.OnTime dTimeDefault, "CreateNewWorksheet(" & Wb & ")"



But it errors!



Please can you help with the syntax?



THANKS



Tim



PS Have searched on Google and John Green kindly helped previously

(2002)
but it was for a fixed parameter rather than a variable (anyway I am

stuck
now!):


http://groups.google.com/group/micro...ing/browse_thr

ead/thread/c5a0ba87b7bc254f/b9bb97043d13dd44?lnk=st&q=Application.Ontime+Par
ameter&rnum=3&hl=en#b9bb97043d13dd44







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
Difference between 2 dates, incl weekends, with variable work days babryanton Excel Discussion (Misc queries) 4 July 11th 06 06:56 PM
Difference between 2 dates, incl weekends, with variable work days babryanton Excel Worksheet Functions 0 July 7th 06 11:24 PM
Help with Application.OnTime [email protected] Excel Programming 1 April 3rd 06 06:02 PM
application.ontime rick Excel Programming 2 July 25th 05 06:09 PM
Application.OnTime -- Unable to Pass Macro with Numeric Parameter Butaambala Excel Programming 7 June 7th 05 10:55 PM


All times are GMT +1. The time now is 10:35 AM.

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"