Excel VBA过程和函数使用基础价赔偿
时间:2023-09-06 05:41:09
过程是构成程序的一个模块,往往用来完成一个相对独立的功能。过程可以使程序更清晰、更具结构性。VBA具有四种过程:Sub过程、Function函数、Property属性过程和Event事件过程。
一.Sub过程
Sub过程的参数有两种传递方式:按值传递(ByVal)和按地址传递(ByRef)。如下例:
Subpassword(ByValxasinteger,ByRefyasinteger)
Ify=100theny=x+yelsey=x-y
x=x+100
Endsub
Subcall_password()
Dimx1asinteger
Dimy1asinteger
x1=12
y1=100
Callpassword(x1,y1)‘调用过程方式:1.Call过程名(参数1,参数2…);2.过程名参数1,参数2…
debug.printx1,y1‘结果是12、112,y1按地址传递改变了值,而x1按值传递,未改变原值
Endsub
二.Function函数
函数实际是实现一种映射,它通过一定的映射规则,完成运算并返回结果。参数传递也两种:按值传递(ByVal)和按地址传递(ByRef)。如下例:
Functionpassword(ByValxasinteger,byrefyasinteger)asboolean
Ify=100theny=x+yelsey=x-y
x=x+100
ify=150thenpassword=trueelsepassword=false
EndFunction
Subcall_password()
Dimx1asinteger
Dimy1asinteger
x1=12
y1=100
ifpasswordthen‘调用函数:1.作为一个表达式放在=右端;2.作为参数使用
debug.printx1
endif
Endsub
三.Property属性过程和Event事件过程
这是VB在对象功能上添加的两个过程,与对象特征密切相关,也是VBA比较重要组成,技术比较复杂,可以参考相关书籍。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Word文档的更改怎么设置
在word中如何设置制表位
常被忽略的Excel2010中10条实用技巧
![](https://img.aspxhome.com/file/2023/1/43201_0s.png)
excel表格勾的符号在哪里怎么输入
熟悉又陌生的word工作界面
![](https://img.aspxhome.com/file/2023/8/35608_0s.png)
手机WPS Office怎么给文档设置密码?
![](https://img.aspxhome.com/file/2023/5/53685_0s.jpg)
word中怎么添加大括号? word文档插入大括号的教程
![](https://img.aspxhome.com/file/2023/2/24702_0s.png)
Word2010文档插入书签交叉引用操作步骤
![](https://img.aspxhome.com/file/2023/3/20793_0s.jpg)
wps表格公式怎么解释
Excel2010如何使用智能的搜索筛选器来对产品库存表进行筛选?
![](https://img.aspxhome.com/file/2023/1/40361_0s.png)
word怎么单独打拼音 word如何输入拼音
![](https://img.aspxhome.com/file/2023/7/32507_0s.png)
word中怎样自动输入编号呢?
![](https://img.aspxhome.com/file/2023/5/23025_0s.jpg)
excel如何制作课程表?用excel制作班级课程表方法介绍
![](https://img.aspxhome.com/file/2023/0/42030_0s.jpg)
EXCEL2007 vlookup函数公式#N/A解决方法
![](https://img.aspxhome.com/file/2023/2/37382_0s.jpg)
在excel中制表格怎样把隐藏的网格显示出来
![](https://img.aspxhome.com/file/2023/6/36596_0s.png)
Word中图片排版只会整齐摆放?
![](https://img.aspxhome.com/file/2023/9/23909_0s.jpg)
Win10专业版应用商店提示错误代码0x80072EE7怎么办?
![](https://img.aspxhome.com/file/2023/0/50100_0s.jpg)
excel表格设置斜线的方法
Word 2007表格怎么设置标题行重复跨页显示
![](https://img.aspxhome.com/file/2023/0/19250_0s.png)
word字体怎么设置?
![](https://img.aspxhome.com/file/2023/4/34304_0s.gif)