VBScript更新Excel电子表格

我浏览过很多网站,其中包括我input标题时出现的所有问题,而且似乎无法让我的程序正常工作。 它激活电子表格,但没有数据打印。

Option Explicit Dim objExcel, objWorkbook Dim strTIN, strName, strFName, strLName, strState, strEmpID, strRecDate, strComment Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\Users\lpeder6\Desktop\Important Info\Data tracking.xlsx") CopyData Set objExcel = Nothing Set objWorkbook = Nothing '---------------CopyData - Copies required data----------------- Sub CopyData() strTIN = "2-123456789-00005" strName = "Smith John " strState = "MN" strEmpID = "S987654321" strRecDate = "04/02/2015" strComment = "This is all that is in my comment." strLName = Trim(Left(strName, 10)) strFName = Trim(Right(strName, 15)) strName = strLName & " " & strFName objExcel.Visible = True objWorkbook.Sheets(1).Activate objWorkbook.Sheets(1).Cells(1, 1).Value = strTIN objWorkbook.Sheets(1).Cells(1, 2).Value = strName objWorkbook.Sheets(1).Cells(1, 3).Value = strState objWorkbook.Sheets(1).Cells(1, 4).Value = strEmpID objWorkbook.Sheets(1).Cells(1, 5).Value = strRecDate objWorkbook.Sheets(1).Cells(1, 6).Value = strComment objExcel.ActiveWorkbook.Close End Sub 

任何想法将不胜感激。

通过“没有数据打印” ,我假设你的意思是你input的数据没有被存储。 这是因为您closures它时不保存工作簿。 将子行中的一行更改为:

 objExcel.ActiveWorkbook.Close true 

请参阅Workbook.Close方法(Excel)以获取完整的语法参考。