VBA入门之一
Private Sub CommandButton1_Click() //按钮事件
etxt = "Hello world!!!"
MsgBox etxt, 64, "宣告"
End SubPrivate Sub CommandButton2_Click()
MsgBox "你点击的单元格是: " & ActiveCell.Address & Chr(13) & "该单元格的值等于: " & ActiveCell.Value, 64, "神算子"
End Sub
VBA入门之二
Sub Macro1() //自动录制宏
' Macro1 Macro
'
'
With ActiveWindow //With语句 集中设置
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
End With
End Sub
Function ShtExist(ByVal ShtName As String) As Boolean //判断指定的工作表是否存在
On Error Resume Next //如果错误.跳出
Dim Sht As Worksheet
Set Sht = Sheets(ShtName)
If Not Sht Is Nothing Then ShtExist = True //Nothing : 一个空的对象引用.
End Function
Sub test()
MsgBox ShtExist("sheet31")
---------------------------------------------------------------------------------------------|
Dim int1 As Worksheet //测试代码
Set int1 = Sheet1
' 'Set int1 = Nothing
' If Not int1 Is Nothing Then
' MsgBox int1.Name
' End If
End Sub