vb笔记

输入窗 mydate = InputBox("请输入日期")
给单元格赋值 Range("c2") = mydate                     
消息框 MsgBox ("添加成功")
 
eles if 实例: '
 Dim mydate
 Dim check
 1: mydate = InputBox("请输入日期")
 check = MsgBox("添加成功", vbYesNo)
 If check = vbYes Then
     Range("c2") = mydate
 Else:
     GoTo 1
 End If
 End Sub
 
do until 列出所有excel文件 
 Dim myrow As Integer
 Dim myfile As String
 myrow = 1
 myfile = Dir("*.xls*")
 Do Until myfile = ""
     Cells(myrow, 1) = myfile
     myrow = myrow + 1
     myfile = Dir
 Loop
 End Sub
 
' selectcase计算星期 Macro Sub selectcase计算星期()
   Dim weeknum As Integer
   Dim mydate As Date
   mydate = CDate(Range("c1"))
   weeknum = Weekday(mydate)
   Select Case weeknum
     Case 1
     MsgBox "星期天"
      Case 2
     MsgBox "星期一"
      Case 3
     MsgBox "星期二"
      Case 4
     MsgBox "星期三"
      Case 5
     MsgBox "星期四"
      Case 6
     MsgBox "星期五"
      Case 7
     MsgBox "星期六"
 Case Else
       MsgBox "计算错误"
     End Select
    
 End Sub
 
删除批注  Dim ws As Worksheet
     Dim cmt As Comment
     For Each ws In Worksheets
         For Each cmt In ws.Comments
         cmt.Delete
         Next
     Next
 End Sub

原文地址:https://www.cnblogs.com/yanweichen/p/9128591.html