Excel VBA系列之MsgBox与InputBox介绍

时间:2021-6-5 作者:qvyue

1. 打开Visual Basic,添加新模块和过程,称之为“test”。

Excel VBA系列之MsgBox与InputBox介绍

Sub test()

End Sub

2. MsgBox是用于弹出一个信息框,其参数如图所示。

Excel VBA系列之MsgBox与InputBox介绍

3. 如图在test过程中输入MsgBox “Hello World!”,然后执行后在Excel中就会出现一个弹窗。

Excel VBA系列之MsgBox与InputBox介绍

Sub test()

MsgBox “Hello World!”

End Sub

4. InputBox是用于弹出一个可以输入信息的弹窗,其参数如图所示。

Excel VBA系列之MsgBox与InputBox介绍

5. 如图在test1过程中输入InputBox “你是几班的?”,然后执行后在Excel会出现一个弹窗需要输入相应的信息。

Excel VBA系列之MsgBox与InputBox介绍

Sub test1()

InputBox “你是几班的?”

End Sub

6. 将MsgBox与InputBox结合在一起使用,定义变量str为字符串,然后str赋值为InputBox,注意这里InputBox后面的参数需要加括号,否则就会报错,然后再执行MsgBox的信息将变量str用于返回的信息中。

Excel VBA系列之MsgBox与InputBox介绍

Sub test2()

Dim str As String

str = InputBox(“你是几班的?”)

MsgBox “我是” & str & “班的”

End Sub

7. 执行以上代码后,先弹出一个InputBox的弹窗,如图。

Excel VBA系列之MsgBox与InputBox介绍

8. 在空白处,我们随意输入,比如“A”。

Excel VBA系列之MsgBox与InputBox介绍

9. 点击上面弹窗的“确定”后,会返回MsgBox的信息。

Excel VBA系列之MsgBox与InputBox介绍

以上示例仅用于演示。

声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:qvyue@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。