|
Private Sub CommandButton1_Click()
Dim wt As Workbook, b, c, d, e
On Error Resume Next
Set b = TextBox5.Value - TextBox1.Value + 1
Set c = TextBox6.Value - TextBox2.Value + 1
Set d = TextBox7.Value - TextBox3.Value + 1
Set e = TextBox8.Value - TextBox4.Value + 1
If TextBox5.Value <> "" Then Val (b) * 0.5
If TextBox6.Value <> "" Then Val (c) * 1
If TextBox7.Value <> "" Then Val (d) * 5
If TextBox8.Value <> "" Then Val (d) * 10
If Val(b) + Val(c) + Val(d) + Val(e) <> ThisWorkbook.Sheets(1).[ad26].Value + ThisWorkbook.Sheets(1).[ag23].Value Then MsgBox "发放票据金额错误!错误值:" & (Val(b) + Val(c) + Val(d) + Val(e)) - (ThisWorkbook.Sheets(1).[ad26].Value + ThisWorkbook.Sheets(1).[ag23].Value), 16, " 警 告!": Exit Sub
Set wt = Workbooks.Open(ThisWorkbook.Path & "\校验收据.xls")
With wt.Sheets(1)
.Visible = -1
.Activate
.Unprotect (4080922)
.Range("d4").Value = TextBox5.Value: .Range("d5").Value = TextBox6.Value: .Range("d6").Value = TextBox7.Value: .Range("d7").Value = TextBox8.Value
.Protect (4080922)
.Sheets(1).Visible = 2
wt.Close True
wt.Quit
Set wt = Nothing
End With
'Unload Me
Unload UserForm41 ' 这句始终执行不了
End Sub
Private Sub UserForm_Initialize()
Dim wt As Workbook, wb As Workbook, i, aa
Set wt = Workbooks.Open(ThisWorkbook.Path & "\校验收据.xls")
With wt.Sheets(1)
.Visible = -1
.Activate
.Unprotect (4080922)
For i = 4 To 8
If Month(.Range("a2").Value) <> Month(Date) And .Range("d" & i).Value <> "" Then
.Range("c" & i).Value = .Range("d" & i).Value + 1
End If
Next i
.Range("a2").Value = Format(Date, "yyyy年m月d日")
.Range("d4:d8").ClearContents
.Protect (4080922)
Set wb = Workbooks.Open(ThisWorkbook.Path & "\交接单.xls", Password:="jy")
wb.Sheets("录入").Unprotect (8812968)
ThisWorkbook.Sheets(1).Unprotect Sheet6.[aa1]
ThisWorkbook.Sheets(1).[ad26].Value = wb.Sheets("录入").Range("ak36").Value
aa = .Range("c4:c7") '起号
ThisWorkbook.Sheets(1).Range("t81:t84") = aa
TextBox1.Value = ThisWorkbook.Sheets(1).Range("t81").Value: TextBox2.Value = ThisWorkbook.Sheets(1).Range("t82").Value: TextBox3.Value = ThisWorkbook.Sheets(1).Range("t83").Value: TextBox4.Value = ThisWorkbook.Sheets(1).Range("t84").Value '生成起始票号
ThisWorkbook.Sheets(1).Protect Sheet6.[aa1]
wb.Sheets("录入").Protect (8812968)
For l = 1 To 4 '锁定文本框
Me.Controls("TextBox" & l).Locked = True
Next
End With
Workbooks("交接单.xls").Close False
Workbooks("校验收据.xls").Close True
Set wt = Nothing
Set wb = Nothing
End Sub
|
|