calling a procedure with parameters

Lino

Active Member
Joined
Feb 27, 2002
Messages
429
I am using the following function and at the same time would like call another procedure with parameters

Application.OnTime (Now + TimeValue("00:00:02"), "Do This"

works just fine

If I try to pass parameters it doesn't

Application.OnTime (Now + TimeValue("00:00:02"), "DoThis(color, day, week)"

any suggestions?

Thanks,

Lino
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Not sure if this will help, but first off, is your sub statement set up to accept parameters? Secondly, I imagine that your use of VBA/Excel Function and Property names for variable names is probably causing problems. When I tried to use your variable names, I got all kinds of errors, changing them to a, b, and c fixed it. I wasn't sure what type of parameter you were trying to send with color.

Example:

Sub doThis(ByRef a As Long, b As Integer, c As Long)
MsgBox "Color=" & a & " Day=" & b & " Year=" & c
End Sub

Sub calldo()
Dim a As Long
Dim b As Integer
Dim c As Long
a = 255
b = 17
c = 2004
Call doThis(a, b, c)
End Sub
 
Upvote 0
this is what i have and it is not working

The parameters are all variables that i assigned values to in the current procedure


Application.OnTime Now + TimeValue("00:00:02"), _
" 'CalculateThis " & DollarAmount & "," & Net & "," & SRow & "," & FinalRow & "," & Tax & " ' "

the vbe doesn't complain but when the code runs an error message comes up and says that it can't find the macro 'CalculateThis.....'

Right below this procedure is another procedure called

Sub CalculateThis(DollarAmount, Net, SRow, FinalRow, Tax)

so I don't know why it can't find it?

Any suggestions?

Lino
 
Upvote 0
These three worked for me in Excel 2000

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> CalculateThis(DollarAmount, Net, SRow, FinalRow, Tax)
    MsgBox DollarAmount
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>


<SPAN style="color:#00007F">Sub</SPAN> Test()
    Application.OnTime Now + TimeSerial(0, 0, 2), _
        "'CalculateThis 1,2,3,4,5 '"
    Application.OnTime Now + TimeSerial(0, 0, 4), _
        "'CalculateThis " & 1 & "," & 2 & "," & 3 & "," & 4 & "," & 5 & " '"
        
    <SPAN style="color:#00007F">Dim</SPAN> DollarAmount <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, Net <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, SRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, FinalRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, Tax <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
    DollarAmount = 1
    Net = 2
    SRow = 3
    FinalRow = 4
    Tax = 5
    
    Application.OnTime Now + TimeSerial(0, 0, 6), _
        "'CalculateThis " & DollarAmount & "," & Net & "," & SRow & "," & FinalRow & "," & Tax & " '"
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Did it work with TimeSerial() ? I like TimeSerial because i like being able to enter hour, minute and seconds separately, but both should work...
 
Upvote 0
I tried Juan's code with time value and it works fine.

Code:
Option Explicit

Sub CalculateThis(DollarAmount, Net, SRow, FinalRow, Tax)
    MsgBox DollarAmount
End Sub


Sub Test()
    Application.OnTime Now + TimeValue("00:00:02"), _
        "'CalculateThis 1,2,3,4,5 '"
    Application.OnTime Now + TimeValue("00:00:04"), _
        "'CalculateThis " & 1 & "," & 2 & "," & 3 & "," & 4 & "," & 5 & " '"
        
    Dim DollarAmount As Long, Net As Long, SRow As Long, FinalRow As Long, Tax As Long
    DollarAmount = 1
    Net = 2
    SRow = 3
    FinalRow = 4
    Tax = 5
    
    Application.OnTime Now + TimeValue("00:00:06"), _
        "'CalculateThis " & DollarAmount & "," & Net & "," & SRow & "," & FinalRow & "," & Tax & " '"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,663
Messages
6,173,652
Members
452,525
Latest member
DPOLKADOT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top