Andy 胡

导航

VBA_Excel_教程:过程,函数

Sub s1()

    Debug.Print "s1"
    '调用过程:无括号,加call提升可读性
    s2
    Call s2
End Sub

Sub s2()
    Debug.Print "s2"
End Sub

函数当过程用完全没有问题

Function f1()
    Debug.Print "f1"
    f2
    Call f2
End Function

Function f2()
    Debug.Print "f2"
End Function

函数是可以有返回值的

Function f1()
    Debug.Print "f1"
    strRet = f2("B")
    Debug.Print strRet
    strRet = f3("C")
    Debug.Print strRet
    
End Function

Function f2(inPara As String) As String
    '函数返回值用【函数名】表示
    f2 = "return f2 " & inPara
End Function

Function f3(inPara) '返回值、参数:加类型声明更安全,提升可读性
    f3 = "return f3 " & inPara
End Function

 

posted on 2016-12-03 11:11  talkwah  阅读(418)  评论(0编辑  收藏  举报