Private Sub Form_Load()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application") ´创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(App.Path & "\1") ´打开已经存在的EXCEL工件簿文件
xlApp.Visible = True ´设置EXCEL对象可见(或不可见)
Set xlSheet = xlBook.Worksheets(1) ´设置活动工作表
xlSheet.Cells(1, 1) = "零件名称" ´给单元格(row,col)赋值
xlSheet.Cells(1, 2) = " 价格"
´xlSheet.PrintOut ´打印工作表
´xlBook.Close (True) ´关闭工作簿
´xlApp.Quit ´结束EXCEL对象
Set xlApp = Nothing ´释放xlApp对象
´xlBook.RunAutoMacros (xlAutoOpen) ´运行EXCEL启动宏
´xlBook.RunAutoMacros (xlAutoClose) ´运行EXCEL关闭宏
End Sub
文章来源于领测软件测试网 https://www.ltesting.net/