ALT+F11 打开编辑器
F1 帮助
F5 运行
1. MsgBox
Public Sub mysub()
MsgBox "今天记得交房租"
End Sub
![](https://img.haomeiwen.com/i646542/8262cb78975777b8.png)
2. Option Explicit 限制了所有的变量必须声明类型
![](https://img.haomeiwen.com/i646542/21be4626a5b2ddeb.png)
![](https://img.haomeiwen.com/i646542/ed7fe485f3ddce0e.png)
Option Explicit
Sub test()
Dim a As String
a = "今天交房租"
MsgBox a
End Sub
![](https://img.haomeiwen.com/i646542/9d7303c130a809a1.png)
3. 把数据存储到变量
[LET] 变量名称=数据
SET 变量名称=对象
给对象变量赋值时,set不能少,给其他变量赋值时,let可以省略
Const 变量名称 AS 数据类型=数值
声明常量时不仅要指定名称及类型,还要赋值
Dim 数组名(a to b) AS 数据类型
声明数组时不仅要指定名称及类型,还应指定数组大小
Sub bb()
Dim str As String
Let str = "加油加油不痛不痛"
Range("A1").Value = str
End Sub
![](https://img.haomeiwen.com/i646542/5d72bab87f700c26.png)
Sub xx()
Dim rng As Range
Set rng = Worksheets("sheet2").Range("A1")
rng.Value = "马上元旦咯"
End Sub
![](https://img.haomeiwen.com/i646542/57349df726863787.png)
网友评论