2016-08-22 56 views
-1

我想運行一個批處理文件使用任務調度程序運行VB腳本。當我手動運行腳本或從Windows 7上的 任務調度程序運行腳本時,它工作正常,但是當我嘗試手動運行它或從某個中央服務器位置的Windows Server 2012 R2上的任務計劃程序運行時, ,然後我得到以下錯誤: Microsoft VBScript運行時錯誤:ActiveX組件不能創建對象: 'Excel.Application'在Windows 2012上的ActiveX組件錯誤

這是我的批處理腳本代碼:

cscript %~dp0\CSV_To_Excel.vbs %1 

這是我的Excel代碼(CSV轉換到Excel) :

Dim Excel 

file = "C:Folder1\Customer.csv"  
Set fso = CreateObject("Scripting.FileSystemObject") 

txt = fso.OpenTextFile(file).ReadAll 

fso.OpenTextFile(file, 2).Write Replace(Replace(txt, "¬", vbTab), Chr(34), "") 

'Set obj = CreateObject("Scripting.FileSystemObject") 'Calls the File System Object 

Const xlDelimited = 1 
Const xlNormal = -4143 

Set Excel = CreateObject("Excel.Application") 
Excel.DisplayAlerts = False 
With Excel 
    .Workbooks.Open "C:Folder1\Customer.csv" 
    .Sheets(1).Columns("A").TextToColumns .Range("A1"), xlDelimited, , , , True 'semicolon-delimited 

    .ActiveWorkbook.SaveAs .ActiveWorkbook.Path & "\Customer", xlNormal 
     'Excel.Saved = True 
     'Excel.Close 
    .Quit 
Excel.DisplayAlerts = True 

    fso.DeleteFile("C:Folder1\Customer.csv") 'Deletes the file throught the DeleteFile function 
End With 

謝謝

回答

相關問題