一是把excel在外部打开
二是把excel按数据库方式打开
你最好给我一个电子的样子,那才能有针对性地写出代码。
张志晨
补充:
1、引用Microsoft Excel类型库
“工程”-“引用”-选择“Microsoft Excel 8.0 Object Library”-“确定”
2、声明显式数据类型,创建新实例并获取Excel的控制句柄
Dim ExcelObject As Excel.Application
Set ExcelObject = CreateObject( "Excel.Application ")
3、调用并显示Excel
Excelobject.Visible = True
4、打开文件,
ExcelObject .Open pathName
然后用循环进行判断,那就简单了。因为不知道你到底要判断什么,所以无法写出具体的代码来。
Public xlApp As Excel.Application
Public xlbook As Excel.Workbook
Public xlSheet As Excel.Worksheet
Public Function OpenExcel(xlPath As String)
Set xlApp = CreateObject("excel.application")
Set xlbook = xlApp.Workbooks.Open(xlPath)
Set xlSheet1 = xlbook.Worksheets(1)
Set xlSheet2 = xlbook.Worksheets(2)
xlApp.Visible = fasle
Dim i As Integer
i = 1
'下面的判断是假设的,你要改成你实际需要的
Do While xlSheet1.Cells(i, 1).Value =xlSheet2.Cells(i, 1).Value
Form1.List1.AddItem xlSheet.Cells(i, 1).Value
i = i + 1
Loop
quitExcel
End Function
Public Function quitExcel()
xlApp.Quit
Set xlApp = Nothing
Set xlbook = Nothing
End Function
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)