首先要创建execl就用对象以后才可以创建工作薄
dim xls as object
dim sheet as object
set xls=createobject("Excel.Application")
set sheet=createobject("xls.sheet")
dim xls as object
dim sheet as object
set xls=createobject("Excel.Application")
set sheet=createobject("xls.sheet")
give you advice later!
Public Sub SaveTestData()
Dim nLoopRow As Integer
Dim nLoopCol As Integer
Dim nChannel As Integer
Dim TempDate
Dim sOutPut(7) As String
Dim strlog As String
nChannel = FreeFile
If fMainForm.grdResults.Cols > 0 ThenOpen App.Path & "\" & App.EXEName & ".csv" For Append As #nChannel
For nLoopRow = 0 To fMainForm.grdResults.Rows - 1
fMainForm.grdResults.Row = nLoopRow 'Ö¸Ïòµ±Ç°ÐÐ
For nLoopCol = 0 To fMainForm.grdResults.Cols - 1
fMainForm.grdResults.Col = nLoopCol
sOutPut(nLoopCol) = fMainForm.grdResults.Text
'Write #nChannel, sOutPut(0),
Next nLoopCol
Write #nChannel, sOutPut(0), sOutPut(1), sOutPut(2), sOutPut(3), sOutPut(4), sOutPut(5), sOutPut(6)
Next nLoopRow
Close #nChannel
End If
End Sub注意:
我是将fMainForm.grdResults (MSFLEXGRID)控件中的内容输出,
ExcelApp.Workbooks.Open FileName:=XlsName
If Val(ExcelApp.Application.Version) >= 8 Then
Set ExcelSheet = ExcelApp.ActiveSheet
Else:
Set ExcelSheet = ExcelApp
End If
你怕不對
用這個方法去檢驗一下﹐看看到底有沒有生成xl對象﹕ Dim xl As Object
Set xl = CreateObject("excel.sheet")
xl.Parent.Visible = True
Set xl = Nothing是OK的