首页 > 其他 > 详细

VBA中常用技巧

时间:2014-01-14 21:25:20      阅读:534      评论:0      收藏:0      [点我收藏+]

常量定义

Public Const i as Integer = 1

 

自定义类型

Type mytype

  i   as Integer

     b  as  Boolean

     s  as  String

end Type

 

错误处理

①跳过出错语句,继续执行

   On Error Resume Next

   处理代码

   On Error Goto 0

②执行错误处理

   On Error Resume Next

   处理代码

   On Error Goto ErrorHandler

   ErrorHandler:

   错误处理代码

 

分支处理

Select case condition

      case "value1"

              详细处理

      case "value2"

              详细处理

      case  else

             详细处理

End Select

 

循环处理

①For i = 1 to j (Step y)

        详细处理

   next i

②For each obj in objs

        详细处理

   next obj

③Do While / Until Condition

   详细处理

   Loop

或Do

         详细处理

    Loop While / Until Condition

 

函数可选参数定义

Function funs(Optional i as Interger) as String

  详细处理

End Function

参数类型是Variant的场合,可用Ismissing(x)判断参数是否赋值

 

函数随机参数定义

Function funs(ParamArray arglist() as Variant) as Integer

End Function

函数有多个参数时,随机参数需定义在最后

VBA中常用技巧

原文:http://www.cnblogs.com/liangx85/p/3513182.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!