在运行vba脚本时,我收到错误Microsoft VBScript运行时错误:所需对象:'DoCmd'

时间:2014-04-28 07:25:16

标签: ms-access vbscript

在通过命令提示符运行vb脚本时,我收到错误,指出Microsoft VBScript运行时错误:所需对象:' DoCmd'

请尽快帮助我。

ExecuteInsert
Sub ExecuteInsert()

Dim sheetPath
Dim dbs, DbFullName, acc
    Set acc = createobject("Access.Application")

    DbFullName = "D:\G\Diamond\FINAL MS-Access\Demo\MS-Access project.accdb"
    Set dbs = acc.DBEngine.OpenDatabase(DbFullName, False, False)

dbs.Execute "Delete from TempRoadMap"

sheetPath = "C:\Users\270784\Desktop\CSPRV scheduled work - 2014 through 1-26-14.xlsx"



DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "TempRoadMap", _
 sheetPath, True

MsgBox "Imported Sheet1 from " & sheetPath & " Successfully!"

dbs.Execute "Delete from RoadMap"
    dbs.Execute "INSERT INTO [RoadMap] ( Release_Name,SPRF,SPRF_CC,Estimate_Type,PV_Work_ID,SPRF_Name,Estimate_Name,Project_Phase,CSPRV_Status,Scheduling_Status,Impact_Type,Onshore_Staffing_Restriction,Applications,Total_Appl_Estimate,Total_CQA_Estimate,Estimate_Total,Requested_Release,Item_Type,Path) SELECT [TempRoadMap.Release Name], [TempRoadMap.SPRF], [TempRoadMap.Estimate (SPRF-CC)],[TempRoadMap.Estimate Type],[TempRoadMap.PV Work ID],[TempRoadMap.SPRF Name],[TempRoadMap.Estimate Name],[TempRoadMap.Project Phase],[TempRoadMap.CSPRV Status],[TempRoadMap.Scheduling Status],[TempRoadMap.Impact Type],[TempRoadMap.Onshore Staffing Restriction],[TempRoadMap.Applications],[TempRoadMap.Total Appl Estimate],[TempRoadMap.Total CQA Estimate],[TempRoadMap.Estimate Total],[TempRoadMap.Requested Release],[TempRoadMap.Item Type],[TempRoadMap.Path] FROM [TempRoadMap] "

 dbs.Close
MsgBox "Done"


End Sub

1 个答案:

答案 0 :(得分:0)

对于

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "TempRoadMap", _
     sheetPath, True

除非您在其他地方定义了acSpreadsheetTypeExcel97,否则您应该使用acSpreadsheetTypeExcel8,请参阅here for the different types

不确定这是否正确,但我看到here您应该使用object.docmd所以在您的情况下会是

acc.docmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel97, "TempRoadMap", _
         sheetPath, True