Issue with passing values

A

associates

Hi,

I was wondering if anyone might be able to help me.

I was trying to create a function that takes 2 arguments and i go
compiler error messages saying i need '=' expected.

Here is my code

filein = Application.GetOpenFilename()
ImportCSV (mysheet, filein)

in the function of ImportCV, i have
Function ImportCSV(sheet As String, inputfile As String)

...

end function

Any ideas?

Thank you in advanc
 
A

Ardus Petus

Sub ImportCSV(sheet As String, inputfile As String)

Since ImportCSV does not return a value, it is a Sub, not a Function

HTH
 
D

Dave Peterson

Try removing the ()'s and make sure you pass the correct type of parms to the
function:

Option Explicit
Sub testme()
Dim mySheet As String
Dim inputfile As String
inputfile = Application.GetOpenFilename()
ImportCSV mySheet, inputfile
End Sub
Function ImportCSV(sheet As String, inputfile As String)
'do the work
MsgBox "hi"
End Function
 
D

Dave Peterson

Ps. You can keep the ()'s if you use Call:

Option Explicit
Sub testme()
Dim mySheet As String
Dim inputfile As String
inputfile = Application.GetOpenFilename()
Call ImportCSV(mySheet, inputfile)
End Sub
Function ImportCSV(sheet As String, inputfile As String)
'do the work
MsgBox "hi"
End Function
 
Top