VBS操作Excel

  1. 打开excel

    Dim objExcel,objWorkbook,objSheet

    Set objExcel=CreateObject("excel.application")

    Set objBook=objExcel.Workbooks.Open("\\MGPCTFSW01\UserFolders$\t165050\Desktop\Portal_Smoke_Automation\Test Data\Book1.xlsx")

  2. 读取Excel

    a.

    Set objSheet=objbook.Sheets("sheet1")

    msgbox objSheet.cells(2,2)

    Set objBook=Nothing

    Set objSheet=Nothing

    objExcel.Quit

b.

Set objSheet=objbook.Sheets(SheetName)

Set objRange = objSheet.UsedRange

objRow = objRange.Find(RowName).Row

objColumn = objRange.Find(ColumnName).Column

objValue = objSheet.Cells(objRow,objColumn)

05-11 11:30