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
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