在 Python 中运行 VBScript:错误 Microsoft VBScript 运行时错误:ActiveX 组件无法创建对象



我在python代码中调用VBScript。我得到错误";ActiveX组件无法创建对象";但当我调用Seperate时(当我双击它或使用cmd运行时(,这很好。

这是python代码的一部分。我试过cscript,wscript。将路径更改为system32/SYSVOW64。但是什么都不起作用

for i in range(printInput):
print("range")
print(i)
os.system(r"C:Windowssystem32cmd.exe /k c:windowsSysWOW64cscript.exe  C:Usersmuneeb.kalathilPycharmProjectsmoodledownloadvcconverterlabelprintnew.vbs")
#subprocess.call("run.bat")

这是VBSscript

'<SCRIPT LANGUAGE="VBScript">
' Data Folder
Const sDataFolder = "C:Usersmuneeb.kalathilPycharmProjectsmoodledownloadvcconverterlabelprint"
DoPrint(sDataFolder & "label.lbx")
'*******************************************************************
'   Print Module
'*******************************************************************
Sub DoPrint(strFilePath)
Set ObjDoc = CreateObject("bpac.Document")
bRet = ObjDoc.Open(strFilePath)
If (bRet <> False) Then
ObjDoc.GetObject("AssetName").Text = "text"
ObjDoc.GetObject("AssetTag").Text = "text"
ObjDoc.GetObject("company").Text = "text"

Call ObjDoc.SetBarcodeData(ObjDoc.GetBarcodeIndex("QR"), "link")
' ObjDoc.SetMediaByName ObjDoc.Printer.GetMediaName(), True
ObjDoc.StartPrint "", 0
ObjDoc.PrintOut 1, 0
ObjDoc.EndPrint
ObjDoc.Close
End If
Set ObjDoc = Nothing
End Sub

它显示中的错误

Set ObjDoc = CreateObject("bpac.Document")

所以经过多次尝试,我将vbscript转换为exe文件,然后执行。现在它正在发挥作用。

os.system("run.exe")

我使用了这个软件,因为有些转换器并没有真正转换为exe。这个软件有一些局限性。但对我来说效果很好。

https://www.battoexeconverter.com/

相关内容

最新更新