将Public Function fact(x As Long) As Long
改为
Public Function fact(byval x As Long) As Long
应该可以
Public Function fact(ByVal x As Long) As Long
Dim i, m As Long
m = 1
For i = 1 To x
m = m * i
Next
fact = m
End Function
Private Sub Form_Click()
Dim k, a As Long
a = 0
For k = 1 To 10
a = a + fact(k)
Next
Print a
End Sub
'byval 指定传值