Dim n As Long
Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.open("D:\Documents and Settings\chaoliu\桌面\2月份考勤bbb.xls")
Set ExcelSheet = ExcelBook.Worksheets(1)
n = 1
Do
MsgBox "第" & n & " 条记录,第一列:" & ExcelSheet.Range("A" & n).Value & _
";第二列:" & ExcelSheet.Range("B" & n).Value
n = n + 1
Loop Until ExcelSheet.Range("A" & n).Value = ""
Set ExcelSheet = Nothing
Set ExcelBook = Nothing
Set ExcelApp = Nothing
使用说明:
*****************************************
VB读Excel文件,创建xls表,并写入内容
Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.Add
Set ExcelSheet = ExcelBook.Worksheets(1) '添加工作页
ExcelSheet.Activate '激活工作页
ExcelApp.DisplayAlerts = False
ExcelSheet.Name="sheet1"
ExcelSheet.Range("A1").Value = 100 '设置A1的值为100
ExcelBook.SaveAs "d:\test.xls" '保存工作表
msgbox "d:\test.xls创建成功!"
ExcelBook.close
set excelApp=nothing
set ExcelBook=nothing
set ExcelSheet=nothing
将以上代码copy到记事本存为"writexls.vbs"文件,可运行测试
读execel文件
Set ExcelApp = CreateObject("Excel.Application") '创建EXCEL对象
Set ExcelBook = ExcelApp.Workbooks.open("d:\test.xls")
Set ExcelSheet = ExcelBook.Worksheets(1)
msgbox ExcelSheet.Range("A1").Value
将以上代码copy到记事本存为"readxls.vbs"文件,可运行测试
以上文章来自于:
http://bbs.54master.com/200898,1,1###
以下内容来自于:
http://topic.csdn.net/t/20040930/09/3420583.html# 判断Excel文件有多少行和多少列
Dim lCols As Long
Dim lRows As Long
lCols = Sheet1.UsedRange.Cells.Columns.Count
lRows = Sheet1.UsedRange.Cells.Rows.Count
MsgBox "用户区有:" & lCols & "列 有:" & lRows & "行"