excel中VBA程序分两种 一种叫过程程序 一种叫函数程序
VBA的过程程序
格式:Sub sub_name()
'
'实现各种操作的VBA代码
'
End Sub
如:Sub 填充()
Range('A1:A10')=1
Cells(1,2)=2
End Sub
sub
过程程序的调用
格式1:
Call 过程名
格式2:
Call 过程名(参数1, 参数2, ...)
Sub函数是一种宏函数可以指定到其他对象执行,如按钮
VBA的函数程序
格式:Function 函数名(参数1, 参数2, ...) As 数据类型
' 需要在函数中执行的代码
函数名 = 函数执行后的结果
End Function
无形参函数
如:Function addl()
dim s as double
s=80^2 2
addl=s*10
End Function
有形参函数
Function subb(a as integer)
subb=a*a
End Function
函数的调用 可以直接用 函数名(参数)
Function ssb(b as integer)
ssb=subb(b)
End function
function
联系客服