运行程序执行时提示这句有问题:
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
程序如下:
Private Sub Command6_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim FileName, SheetName As String
FileName = "e:\data.xls" '要访问的工作簿路径和名称
SheetName = "sheet1" '指定的要访问的工作表名称
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(FileName) '打开已经存在的EXCEL工件簿文件
xlApp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlSheet = xlBook.Worksheets(SheetName) '设置活动工作表
xlSheet.Cells(5, 2) = 2 '给单元格B5赋值
xlSheet.Cells(2, 3) = 3 '给单元格C2赋值
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
End Sub
安装的办公软件的问题,添加控件即可