1,217
社区成员
发帖
与我相关
我的任务
分享'先引用 Microsoft Excel 11.0 Object Library
Option Explicit
Private Sub Command1_Click()
Dim i As Long, n As Long
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
xlApp.Workbooks.Open "C:\Book1.xls"
Set xlBook = xlApp.Workbooks(1) '设置工作薄1
Set xlSheet = xlApp.Worksheets(1) '设置sheet1表
xlBook.Sheets(1).Select '设置sheet1表
'Set xlApp = CreateObject("Excel.Application")
'Set xlBook = xlApp.Workbooks.Open("c:\blue-sun.cn.xls")
'Set xlSheet = xlBook.Worksheets(1)
For i = 1 To 10 'i行
For n = 1 To 4 'n列
xlSheet.Cells(i, n) = 2 * n * i '向表格中添加数据
Next
Next
xlBook.Save '保存为文件
xlApp.Visible = True '显示表格
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub