使用Vbscript操作Excel的示例代码2013-10-12 本站 cat我们可以用Vbscript快速的批处理一些Excel文件。Vbscript脚本需要保存为.vbs文件,双击运行,非常方便。以下为示例代码,请保存为 run.vbs 文件:" on error resume next" define params:im ExcelAppim objWorkBookim objImportSheetim pathpath = "C:/Users/Administrator/Desktop"" open excel:" From http://www.bianceng.cnSet ExcelApp = CreateObject("Excel.Application")ExcelApp.Visible = FalseSet objWorkBook = ExcelApp.Workbooks.Open(path & "/1.xls")Set xlsSheet = objWorkBook.Sheets("Sheet1") "页数名称" read datas:msgbox "第一行第一列数值: " & xlsSheet.Cells(1,1).Valuemsgbox "第二行第一列数值: " & xlsSheet.Cells(2,1).Valuemsgbox "第二行第二列数值: " & xlsSheet.Cells(2,2).Value" set cells data:xlsSheet.Cells(3,1).Value="插入的数据..."msgbox "第三行第一列数值: " & xlsSheet.Cells(3,1).Value" saveobjWorkBook.SaveAs path & "/new.xls""objWorkBook.Save" closeobjWorkBook.Close" clean & quit:ExcelApp.QuitSet objWorkBook = NothingSet objImportSheet = NothingSet ExcelApp = Nothing