发布网友 发布时间:2024-10-19 18:20
共1个回答
热心网友 时间:2024-11-20 08:12
Private Sub Command1_Click()Dim xlsApp As Object, xlsWb As Object, xlsWorksheet As ObjectSet xlsApp = CreateObject(\"excel.application\") '创建excel.application对象xlsApp.Visible = True '显示excel 主界面xlsApp.Visible = False '隐藏excel 主界面xlsApp.workbooks.Open (\"D:\\1\\1.xls\") '打开D:\\1\\1.xlsSet xlsWb = xlsApp.workbooks(\"1.xls\") '设置xlswb变量引用1.xls 工作簿'MsgBox xlsWb.Name '显示工作薄的名字Set xlsWorksheet = xlsWb.worksheets(1) '设置xlsworksheet变量引用1.xls 工作簿的第一个工作表MsgBox xlsWorksheet.cells(1, 1) '显示a1单元格的内容MsgBox xlsWorksheet.cells(1, 2) '显示a1单元格的内容Text1.Text = xlsWorksheet.cells(1, 1)Text2.Text = xlsWorksheet.cells(1, 2)xlsApp.quit'关闭excelEnd Sub