|
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
End With
'Unload Me
Unload UserForm41' 这句无法关闭此用户窗体,换成“Unload Me”还是无法关闭的问题
End Sub
|
|