VBA,如何将函数作为另一个函数的参数传递

时间:2019-01-21 09:58:21

标签: vba function ms-word return

将函数作为另一个函数的参数传递

Sub transliterate() 
  somecode
  ...
  ...
  ...

  return word(a,b)
End Sub 

sub word(x,y)


end sub 

1 个答案:

答案 0 :(得分:0)

VBA不使用return传回函数的结果。 VBA使用以下类型的构造,其中将结果分配给函数名称。达到End Function后,将返回分配给函数名称的值。

Sub testTransliterate()
  Dim a As String, b As String, Result As String

  a = "one"
  b = "two"
  Result = transliterate(x(a), b)
  Debug.Print Result
End Sub

Function x(a As String) As String
    x = a & " test"        
End Function

Function transliterate(x, y) As String
    Dim Result As String

   Result = y & ", " & x
   transliterate = Result
End Function