以下对Excel进行循环写入有什么问题///另外哪位仁兄能为我提供一些有关Excel文件读写操作的代码?多多感谢!多多给分!
Private Sub Command1_Click()
Dim j As Integer
Let j = 1:text1.text=123: text2.text=321
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add
a:
xlSheet.Cells(1, j).Value = Text1.Text
xlSheet.Cells(2, j).Value = Text2.Text
xlSheet.Cells(3, j).Formula = "=R1C1+R2C2"
Text3.Text = xlSheet.Cells(3, 1)
xlSheet.SaveAs "h:\temp.xls"
xlApp.Quit
' If xlSheet.Cells(i, j) <> "" Then
' j = j + 1'GoTo a
'End If
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
End Sub
Private Sub Command1_Click()
Dim j As Integer
Let j = 1:text1.text=123: text2.text=321
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add
a:
xlSheet.Cells(1, j).Value = Text1.Text
xlSheet.Cells(2, j).Value = Text2.Text
xlSheet.Cells(3, j).Formula = "=R1C1+R2C2"
Text3.Text = xlSheet.Cells(3, 1)
xlSheet.SaveAs "h:\temp.xls"
xlApp.Quit
' If xlSheet.Cells(i, j) <> "" Then
' j = j + 1'GoTo a
'End If
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
End Sub
改为下句,放在最后。
xlapp.quit