You're doing a few things wrong here. First, as others have noted in the comments, Set
is a special keyword for assigning Object
variables, and thus Set
will cause an error here.
Next, you must be sure to properly assign back to your function call. Currently your code:
Public Function popu()
Dim Vars() As String
Set Vars = GetVars()
End Function
Is doing four things wrong.
Vars()
is not equal to Vars()
.
GetVars()
is not equal to Public Function GetVariables()
You shouldn't include an empty parentheses on a function call.
Arrays should be declared as Variant
. You can declare an array as a String()
, which creates a string array, but this is generally avoided. Addiitonally, you could declare your variable as a Variant()
but this will cause issues if you ever try to return a null value (such as vbNullString
, or Empty
).
Therefore, your code should be:
Public Function GetVariables() As Variant
Dim Variables As Variant
GetVariables = Variables
End Function
' Make sure your function has an explicit returntype, even if that return is variant.
Public Function popu() as Variant
Dim Variables As Variant
Variables = GetVariables
End Function
As Paul demonstrates in his answer, your array can be instantiated with dimensions pre-defined, and you can hardcode the values into your array. It definitely depends on your application, but you will want to read the documentation on arrays to understand the different uses and methods for creating them.