Private Sub Command1_Click()
Dim excel_app As Object
Dim excel_sheet As Object
Dim lh1, lh2, lh3 As String
Dim lh4, lh5, lh6 As Double
Dim lh7 As String
Dim i, s As Integer
Dim str
Screen.MousePointer = vbHourglass
DoEvents
Set excel_app = CreateObject("excel.application")
excel_app.Workbooks.Open FileName:=App.Path & "\book1"
If Val(excel_app.Application.Version) >= 8 Then
Set excel_sheet = excel_app.ActiveSheet
Else
Set excel_sheet = excel_app
End If
i = Val(Text1.Text) //是这儿不对吗?
s = 4
a1:
Do While Not i = Val(Text2.Text)
excel_app.sheets(2).Select
Set excel_sheet = excel_app.ActiveSheet
lh1 = excel_sheet.cells(i, 3)
lh2 = excel_sheet.cells(i, 4)
lh3 = excel_sheet.cells(i, 5)
lh4 = excel_sheet.cells(i, 6)
lh5 = excel_sheet.cells(i, 7)
lh6 = excel_sheet.cells(i, 8)
lh7 = excel_sheet.cells(i, 14)
str = excel_sheet.cells(i, 22)
If excel_sheet.cells(i, 21) = "" Then
excel_app.sheets(3).Select
Set excel_sheet = excel_app.ActiveSheet
excel_sheet.cells(s, 2) = lh1
excel_sheet.cells(s, 3) = lh2
excel_sheet.cells(s, 4) = lh3
excel_sheet.cells(s, 5) = lh4
excel_sheet.cells(s, 6) = lh5
excel_sheet.cells(s, 7) = lh6
excel_sheet.cells(s, 8) = lh7
i = i + 1
s = s + 1
GoTo a1
Else
i = i + 1
GoTo a1
End If
Loop
excel_app.activeworkbook.save
MsgBox "已成功!"
excel_app.Quit
Set excel_sheet = Nothing
Set excel_app = Nothing
Screen.MousePointer = vbDefault
End Sub
Private Sub Text1_Change()
Dim keyascii
If (keyascii > 47 And keyascii < 58) Or keyascii = 8 Or keyascii = 46 Then
keyascii = keyascii
Else
keyascii = 0
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 8 Then
KeyAscii = 0
End If
If KeyAscii = 46 And InStr(Text1.Text, ".") > 0 Then
KeyAscii = 0
End If
End Sub
sub command1_click()
if isnumeric(text1.text) then
select case val(text1.text)
case 123
'输入的是123,执行相应的代码写在这里
case 456
'输入的是456,执行相应的代码写在这里
case else
'输入的不是123也不是456,执行相应的代码写在这里
end select
else
msgbox "不是数字"
end if
end sub