这是我现在写的
Option Explicit
Dim xlapp As Variant
Dim xlBook As Variant
Dim xlSheet As Variant
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim f As Integer
Dim g As Integer
Private Sub Command1_Click()
a = a + 2
b = b + 3
c = c + 4
d = d + 5
e = e + 6
f = f + 7
g = g + 8
xlSheet.Cells(1, a) = Text2.Text
xlSheet.Cells(1, b) = Text3.Text
xlSheet.Cells(1, c) = Text4.Text
xlSheet.Cells(1, d) = Text5.Text
xlSheet.Cells(1, e) = Text6.Text
xlSheet.Cells(1, f) = Text7.Text
xlSheet.Cells(1, g) = Text8.Text
End Sub
Private Sub Form_Load()
Set xlapp = CreateObject("excel.application")
xlapp.Visible = True
Set xlBook = xlapp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
MSComm1.Settings = "9600,n,8,1"
= 3
MSComm1.NullDiscard = False
MSComm1.RThreshold = 57
MSComm1.InputMode = comInputModeText
MSComm1.PortOpen = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
xlapp.Quit '关闭EXCEL
Set xlapp = Nothing '释放EXCEL对象
End Sub
Private Sub MSComm1_OnComm()
Text1.Text = MSComm1.Input
Text2.Text = Mid(Text1, 6, 10)
Text3.Text = Mid(Text1, 17, 8)
Text4.Text = Mid(Text1, 33, 6)
Text5.Text = Mid(Text1, 39, 3)
Text6.Text = Mid(Text1, 44, 2)
Text7.Text = Mid(Text1, 49, 4)
Text8.Text = Mid(Text1, 54, 2)
End Sub