用VB计算出来的数据,如何直接excel输出?

如题所述

'菜单“工程/引用”,勾选Microsoft Excel 11库,必须的
Private Sub baocun()

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then Set xlApp = CreateObject("Excel.Application")
On Error GoTo prcERR
Set xlBook = xlApp.Workbooks.Open("c:\1.xls") '打开你的EXCEL文件
Set xlSheet = xlBook.Worksheets(1) '第一个表格
xlSheet.Application.Visible = True '设置Excel 可见
xlSheet.Cells(2, 1) = Text1.Text '第2行第一列
xlBook.Save
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Exit Sub
prcERR:
Debug.Print Err.Number & ":" & Err.Description
End Sub
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜