在Windows 2012上的ActiveX组件错误
问题描述:
我想运行一个批处理文件使用任务调度程序运行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
谢谢
答
假设Office安装在服务器上,您可能需要注册activeX组件。 https://support.office.com/en-us/article/Add-or-register-an-ActiveX-control-8fc743a1-e72b-4b55-af3a-85d326e53918