Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA - call function without return variable

Tags:

excel

vba

i have function:

Function importCSV(fileName As Variant) As Boolean

' some code
' no importCSV = TRUE

end Function

i call this function

importCSV (fileName As Variant)

every do OK, bud when a modific function.

Function importCSV(fileName As Variant, linkToHeader As Boolean) As Boolean
    ' some code
    ' no importCSV = TRUE

end Function

i cant call function like this

importCSV (fileName As Variant, TRUE)

VBA detect syntax error and a must call

a = importCSV(fileName As Variant, TRUE)

Why?

like image 819
Miroslav Kolouch Avatar asked Apr 05 '17 10:04

Miroslav Kolouch


People also ask

How do you call a function with a parameter in VBA?

You call a Function procedure by using the function name, followed by the argument list in parentheses, in an expression.

What does not return a value in VBA?

A sub performs a task but does not return a value. A function returns a value of the tasks performed. Subs can be recalled from anywhere in the program and in multiple types.

How do you call a function in VBA?

To call a Sub procedure from another procedure, type the name of the procedure and include values for any required arguments. The Call statement is not required, but if you use it, you must enclose any arguments in parentheses.

Can a VBA sub return value?

Sub procedures DO NOT Return a value while functions may or may not return a value. Sub procedures CAN be called without a call keyword. Sub procedures are always enclosed within Sub and End Sub statements.


1 Answers

To avoid assigning the return value to any variable you can use call keyword

call importCSV(fileName As Variant, TRUE)

Additionally you can call the function this way:

importCSV fileName:="File name", linkToHeader:=TRUE
like image 52
Marius Katinas Avatar answered Oct 23 '22 06:10

Marius Katinas