有两方式,直接引用Excel并创建对象如
dim xlApp as Excel.Application
dim xlBook as As Excel.Workbook
dim xlSheet as As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open("文件名") '打开已经存在的EXCEL工件簿文件
xlApp.Visible = True '设置EXCEL对象可见(False不可见)
Set xlSheet = xlBook.Worksheets("表名") '设置活动工作表
xlSheet.Cells(row, col) =值 '给单元格(row,col)赋值
可以这样:a =xlSheet.Cells(row, col)
另一种是ado,方法网上很多,
如果不引用 可以这样:
dim xlApp as object
dim xlBook as As object
dim xlSheet as As object
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open("文件名") '打开已经存在的EXCEL工件簿文件
xlApp.Visible = True '设置EXCEL对象可见(False不可见)
Set xlSheet = xlBook.Worksheets("表名") '设置活动工作表
xlSheet.Cells(row, col) =值 '给单元格(row,col)赋值
可以这样:a =xlSheet.Cells(row, col)
温馨提示:答案为网友推荐,仅供参考