Passing argument via the calling procedure

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
Office Version
  1. 365
  2. 2019
Platform
  1. Windows

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I 'spose you could try reading the Call Statement help page in VBA.

Rich (BB code):
Syntax

[Call] name [argumentlist]

The Call statement syntax has these parts:

Part Description 

Call -- Optional; keyword. If specified, you must enclose argumentlist in parentheses. For example: 

 Call MyProc(0) 
 
name -- Required. Name of the procedure to call. 

argumentlist -- Optional. Comma-delimited list of variables, arrays, or expressions to pass to the procedure.
 Components of argumentlist may include the keywords ByVal or ByRef to describe how the arguments are
 treated by the called procedure. However, ByVal and ByRef can be used with Call only when calling a DLL procedure.
 On the Macintosh, ByVal and ByRef can be used with Call when making a call to a Macintosh code resource. 

Remarks

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword
 to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the
 Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call
 any intrinsic or user-defined function, the function's return value is discarded.

To pass a whole array to a procedure, use the array name followed by empty parentheses.
 
Upvote 0
PS.... The use of ByVal seems redundant, at best. In fact, it seems to cause errors (sometimes aborts) -- surprise! Perhaps I misunderstand its valid use or purpose.

Rich (BB code):
Option Explicit

Public Declare Function QueryPerformanceFrequency Lib "kernel32" _
   (ByRef freq As Currency) As Long
   
Sub testit()
Dim f As Currency

' call by ref; f changed as expected
f = -1
QueryPerformanceFrequency f
MsgBox f

' call by val; f not changed, as expected
f = -1
QueryPerformanceFrequency (f)
MsgBox f

' call by ref; f changed as expected
f = -1
Call QueryPerformanceFrequency(f)
MsgBox f

' call by val; f not changed, as expected
f = -1
Call QueryPerformanceFrequency((f))
MsgBox f

' caveat: this sometimes aborts program
' on my computer (Excel 2010 with Win 7).
' otherwise, it just causes a runtime error

' call using ByVal syntax
' (note: redundant ByRef is not allowed!)
f = -1
Call QueryPerformanceFrequency(ByVal f)
MsgBox f
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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