- ·上一篇教育:excel文件关联被改变如何办
- ·下一篇教育:excel不同页数字如何加总数
excel如何只能输入一次
1.如何设定EXCEL表格,每天只能输入一次数据
打开Excel工作表,按Alt+F11打开编辑器,输入如下代码:
Dim FileNum As Integer, nDate As String
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Me.Saved = True Then
FileNum = FreeFile
If nDate = "" Then
MsgBox ActiveWorkbook.Path & "\A.txt"
Open ActiveWorkbook.Path & "\A.txt" For Append As #FileNum
Print #FileNum, Date
Close #FileNum
End If
End If
End Sub
Private Sub Workbook_Open()
Dim Lstr As String
nDate = ""
If Dir(ActiveWorkbook.Path & "\A.txt") <> "" Then
FileNum = FreeFile
Open ActiveWorkbook.Path & "\A.txt" For Input As #FileNum
Do While Not EOF(FileNum)
Line Input #FileNum, Lstr
Lstr = Replace(Lstr, " ", "")
If Lstr = Date Then
nDate = 1
Sheet1.Protect Password:="12345"
End If
Loop
Close #FileNum
End If
If nDate <> "" Then
MsgBox "今日已输入过数据,不能再次输入!"
End If
End Sub
说明:
ActiveWorkbook.Path & "\A.txt" 是指工作表所在的目录下的A.txt文件,这个可以根据需要改成其它目录,比如"C:\B.txt"
Sheet1.Protect Password:="12345"中的12345为保护工作表的密码,这个可以根据需要改成自己的密码.
以上代码能锁定名为sheet1的工作表
