vb插入OLE控件,引用Excel,如何定义对象变量。 5
Maxrow=OLE1.object.sheets(1).usedrange.rows.Count'获取excel中行数Maxcol=OLE1.object.sheets...
Maxrow = OLE1.object.sheets(1).usedrange.rows.Count '获取excel中行数
Maxcol = OLE1.object.sheets(1).usedrange.Columns.Count '获取excel中列数
Cell(j, 1) = OLE1.object.sheets(1).Cells(j, 1).Value
谢谢!!!
直接插入excel时,与插入路径有关,必须保留excel文件;而使用OLE控件,再引用excel文件时,是将excel文件插入到vb界面,而与插入路径无关。不知理解对不对,请指导,谢谢! 展开
Maxcol = OLE1.object.sheets(1).usedrange.Columns.Count '获取excel中列数
Cell(j, 1) = OLE1.object.sheets(1).Cells(j, 1).Value
谢谢!!!
直接插入excel时,与插入路径有关,必须保留excel文件;而使用OLE控件,再引用excel文件时,是将excel文件插入到vb界面,而与插入路径无关。不知理解对不对,请指导,谢谢! 展开
2个回答
展开全部
Dim Maxrow, Maxcol As Integer
Dim Cell(10, 10) As Integer
Dim j As Integer
Dim x As Excel.Application
Dim xbook As Excel.Workbook
Dim xsheet As Excel.Worksheet
Set x = CreateObject("excel.application")
s_path = App.Path & "\Book1.xls"
Set xbook = x.Workbooks.Open(s_path)
Set xsheet = x.Worksheets("sheet1")
j = 1
Maxrow = xsheet.usedrange.rows.Count '获取excel中行数
Maxcol = xsheet.usedrange.Columns.Count '获取excel中列数
Cell(j, 1) = xsheet.Cells(j, 1).Value
展开全部
直接使用excel
Dim x As Excel.Application
Dim xbook As Excel.Workbook
Dim xsheet As Excel.Worksheet
Set x = CreateObject("excel.application")
s_path = App.Path & "\test.xls"
Set xbook = x.Workbooks.Open(s_path)
Set xsheet = x.Worksheets("sheet1")
Dim x As Excel.Application
Dim xbook As Excel.Workbook
Dim xsheet As Excel.Worksheet
Set x = CreateObject("excel.application")
s_path = App.Path & "\test.xls"
Set xbook = x.Workbooks.Open(s_path)
Set xsheet = x.Worksheets("sheet1")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询