请教这个VBS 脚本怎么写?
一个EXCEL表中有A B C D 四列,打印出A列中(只有YES和NO)为YES值时,B C D 列中的内容? 目的是干嘛啊,VBS从外部去读EXCEL? 那就判断A列值输出其他就是了这种东西还是EXCEL自己做过滤方便啊,一个筛选就好了 将excel导进qtp中,然后进行操作要方便的多。 看看 CodeSamplesPlus 里面有啊 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
页:
[1]