|
'稍作修改,我现在的电脑上有office2016、2010,并不清楚创建的是哪一个版本的对象,不过运行正常
Option Explicit
Private Sub ComCalculation_Click()
Dim point_num As Integer, CDS_num
Dim xlApp, xlBook, xlSheet
point_num = 100
Dim tD() As Double, ft() As Double, D_ft() As Double
ReDim tD(point_num), ft(point_num), D_ft(point_num), CDS(CDS_num)
Dim i As Integer
For i = 0 To point_num - 1
tD(i) = 0.01 * 10# ^ (9# * i / 99)
ft(i) = tD(i) * 2
D_ft(i) = tD(i) * 5
Next
Set xlApp = CreateObject("Excel.Application") '创建excel对象
xlApp.Visible = False '不显示打开的Excel
Set xlBook = xlApp.Workbooks.Add()
Set xlSheet = xlBook.Worksheets(1) '打开EXCEL工作表
Dim j As Integer
For j = 0 To 99
xlSheet.Cells(j + 1, 1) = tD(j) 'Format(tD(j), "0.00000")
xlSheet.Cells(j + 1, 2) = ft(j) ' Format(ft(j), "0.00000")
xlSheet.Cells(j + 1, 3) = D_ft(j) 'Format(D_ft(j), "0.00000")
Next
xlBook.SaveAs App.Path & "\test.xlsx"
xlBook.Close (True) '关闭并保存
xlApp.DisplayAlerts = False '关闭EXCEL不提示保存
xlApp.Quit '关闭EXCEL
Set xlBook = Nothing '释放设置的资源
Set xlSheet = Nothing
Set xlApp = Nothing
MsgBox "Finish!"
End Sub
Private Sub ComEnd_Click()
Unload Me
End Sub |
|