在excle中怎样执行主过程和子过程?

2025-11-04 21:11:23

1、打开excle软件,进入VBA的编程界面,打开其中一个模块进行编辑,事先做好了几个子过程和函数,GetUsername,GetFirst,GetLast,DisplayLastFirst

在excle中怎样执行主过程和子过程?

2、接着是设置主过程,也就是程序执行的入口,命名为username

在excle中怎样执行主过程和子过程?

3、然后定义变量

Dim full As String, first As String, last As String

在excle中怎样执行主过程和子过程?

4、接着是调用子过程GetUsername。

Call GetUsername(full)

在excle中怎样执行主过程和子过程?

5、再调用GetFirst,获得名字的第一个。

first = GetFirst(full)

在excle中怎样执行主过程和子过程?

6、调用GetLast,获得名字的最后一个。

last = GetLast(full)

在excle中怎样执行主过程和子过程?

7、最后调用DisplayLastFirst,用来输出名字。

Call DisplayLastFirst(first, last)

完整代码如下:

Sub UserName()    Dim full As String, first As String, last As String    Call GetUsername(full)    first = GetFirst(full)    last = GetLast(full)    Call DisplayLastFirst(first, last)    End Sub

Sub GetUsername(fullname As String)        fullname = InputBox("请输入你的第一个名字和最后一个名字")

End SubFunction GetFirst(fullname As String)    Dim space As Integer    space = InStr(fullname, " ")        GetFirst = Left(fullname, space - 1)

End Function

Function GetLast(fullname As String)    Dim space As Integer    space = InStr(fullname, " ")    GetLast = Right(fullname, Len(fullname) - space)    End FunctionSub DisplayLastFirst(first, last)    MsgBox first & "," & last

End Sub

在excle中怎样执行主过程和子过程?

8、最后运行这个程序。

在excle中怎样执行主过程和子过程?

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢