TA的每日心情 | 开心 2015-10-19 13:26 |
---|
签到天数: 2 天 连续签到: 2 天 [LV.1]测试小兵
|
Dim oExcel,oBook,oSheet
Dim filePath,sheetIndex
'打开的文件路径及Sheet Index
filePath = "D:\Test.xlsx"
sheetIndex = 1
'创建Excel对象
Set oExcel = CreateObject("Excel.Application")
'打开时可见
oExcel.Visible = True
'关闭时不显示警告
oExcel.DisplayAlerts = False
Set oBook = oExcel.Workbooks.Open(filePath)
Set oSheet = oBook.Worksheets(sheetIndex)
With oSheet
'遍历所有行
For i=1 To .UsedRange.Rows.Count
If Trim(.Range("A"&i).FormulaR1C1) = "YES" Then
'去掉了前后空格
MsgBox "B"&i&" = "&Trim(.Range("B"&i).FormulaR1C1)
MsgBox "C"&i&" = "&Trim(.Range("C"&i).FormulaR1C1)
MsgBox "D"&i&" = "&Trim(.Range("D"&i).FormulaR1C1)
End If
Next
End With
'关闭文件
oBook.Close
oExcel.Quit
Set oSheet = Nothing
Set oBook = Nothing
Set oExcel = Nothing |
|