简体   繁体   English

Excel VBA 编写内嵌 VBScript - 运行时错误“429”:ActiveX 组件无法创建对象

[英]Excel VBA Writing in-line VBScript - Run-time error '429': ActiveX component can't create object

I am trying to import CSV file into MS Excel (2016) using VBA Code.我正在尝试使用 VBA 代码将 CSV 文件导入 MS Excel (2016)。 Manipulating import didn't work so far, Excel uses windows system delimiter every time over what I am trying to set in VBA import.到目前为止,操作导入不起作用,Excel 每次都使用 Windows 系统分隔符,而不是我尝试在 VBA 导入中设置的内容。

So, I thought to use a VBScript to change system delimiter from 'comma' to 'Tab' at first, import CSV file, then set system delimiter back to 'comma'.所以,我想首先使用 VBScript 将系统分隔符从“逗号”更改为“制表符”,导入 CSV 文件,然后将系统分隔符设置回“逗号”。

Having VBScript as separate file and running it by:将 VBScript 作为单独的文件并通过以下方式运行它:

    Shell "wscript D:\Hutsul\ChangeDelimiter.vbs", vbNormalFocus

Works, but VBA needs to run on other machines, and for ease of use I wanted to try and code VBScript in-line within Excel VBA environment.有效,但 VBA 需要在其他机器上运行,为了便于使用,我想尝试在 Excel VBA 环境中内嵌编写 VBScript。 Code that I have written stops at Set scr = New ScriptControl and throws: Run-time Error '429': ActiveX component can't create object我编写的代码在Set scr = New ScriptControl处停止并抛出:运行时错误“429”:ActiveX 组件无法创建对象

Tried set scr = CreateObject("MSScriptControl.ScriptControl") didn't help.尝试set scr = CreateObject("MSScriptControl.ScriptControl")没有帮助。 Also, here is a snip of my VBAProject References:另外,这里是我的 VBAProject 参考的片段:

  • Visual Basic For Applications Visual Basic 应用程序
  • Microsoft Excel 16.0 Object Library Microsoft Excel 16.0 对象库
  • OLE Automation OLE自动化
  • Microsoft Office 16.0 Object Library Microsoft Office 16.0 对象库
  • Microsoft ActiveX Data Objects 6.1 Library Microsoft ActiveX 数据对象 6.1 库
  • Microsoft HTML Object Library微软 HTML 对象库
  • Microsoft Scripting Runtime Microsoft 脚本运行时
  • Microsoft VBScript Regular Expressions 5.5 Microsoft VBScript 正则表达式 5.5
  • Microsoft Script Control 1.0微软脚本控制 1.0
  • Microsoft Scriptlet Library Microsoft Scriptlet 库

Below is my VBA code for in-line script (Separate Script file contains just what's in scriptCode lines:下面是我的scriptCode脚本的 VBA 代码(单独的脚本文件只包含scriptCode行中的内容:

'Execute VBScript directly from VBA to change system delimiter from COMMA to TAB
Dim scriptCode As String
Dim scr As ScriptControl: Set scr = New ScriptControl
scriptCode = ""
scriptCode = scriptCode & "Set sh = CreateObject(""WScript.Shell"")"
scriptCode = scriptCode & "Path = ""HKCU\Control Panel\International\sList"""
scriptCode = scriptCode & "Set Separator = CreateObject(""Scripting.Dictionary"")"
scriptCode = scriptCode & "Separator.Add True, ""\t"""
scriptCode = scriptCode & "Separator.Add False, "","""
scriptCode = scriptCode & "sh.RegWrite Path, Separator(sh.RegRead(Path) = "",""), ""REG_SZ"""

scr.Language = "VBScript"
scr.AddCode scriptCode
scr.Run scriptCode

Also, when the script itself is executed (as a separate .vbs file for now) multiple times , it switches delimiter , instead of just setting from 'comma' to 'Tab' and keeping it that way, so if delimiter is already 'Tab' and I run script again, delimiter becomes 'comma' again.此外,当脚本本身被多次执行(目前作为一个单独的 .vbs 文件)时,它会切换 delimiter ,而不是仅仅将“逗号”设置为“Tab”并保持这种方式,因此如果分隔符已经是“Tab” ' 然后我再次运行脚本,分隔符再次变为“逗号”。

Any help is greatly appreciated, thank you!非常感谢任何帮助,谢谢!

You can run VBScript on a 64-bit Windows as a 32-bit process or a 64-bit process.您可以在 64 位 Windows 上将VBScript作为 32 位进程或 64 位进程运行。 I believe you have a 64 bit system and hence when you double click it, it is running it as 32-bit.. resulting in error.我相信你有一个 64 位系统,因此当你双击它时,它以 32 位运行......导致错误。 If you are running 32-bit, then you need the 32-bit ActiveX and if running 64-bit, then you need the 64-bit ActiveX.如果运行 32 位,则需要 32 位 ActiveX;如果运行 64 位,则需要 64 位 ActiveX。

To run a 32-bit VBScript on a 64-bit system, try this要在 64 位系统上运行 32 位 VBScript,试试这个

Create a new VBS file called Test.Vbs and save it at as C:\\Temp\\Test.Vbs Type these two lines in that file.创建一个名为Test.Vbs的新 VBS 文件并将其另存为C:\\Temp\\Test.Vbs在该文件中键入这两行。

Set scr = CreateObject("MSScriptControl.ScriptControl")
MsgBox "Success"

Now press Win + R to launch Run .现在按Win + R启动Run Type this输入这个

C:\windows\sysWOW64\cscript C:\Temp\test.vbs

Does it run now?现在运行了吗? Do you see the message box "Success"?您看到消息框“成功”了吗?

If the above doesn't run then try this如果上面没有运行,那么试试这个

C:\windows\system32\cscript C:\Temp\test.vbs     

One of them will run.其中之一将运行。

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID\{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}]
@="ScriptControl Object"
"AppID"="{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Wow6432Node\AppID\{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}]
"DllSurrogate"=""

[HKEY_CURRENT_USER\SOFTWARE\Classes\AppID\{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}]
"DllSurrogate"=""

This reg file enables MSScriptControl for x64 programs by forcing MSScript's 32 bit DLLs into the 32 bit DLLHost allowing 64 bit programs to access this 32 bit dll.这个 reg 文件通过强制 MSScript 的 32 位 DLL 进入 32 位 DLLHost 允许 64 位程序访问这个 32 位 dll,从而为 x64 程序启用 MSScriptControl。 COM objects in exe files can be accessed by both 64 and 32 bit programs. 64 位和 32 位程序都可以访问 exe 文件中的 COM 对象。

As Regedit requires admin permissions to start, if not an Admin use this batch file to merge the reg file as reg.exe doesn't require admin permissions to start.由于 Regedit 需要管理员权限才能启动,如果不是管理员,请使用此批处理文件合并 reg 文件,因为 reg.exe 不需要管理员权限才能启动。 The registry file only contains per user settings which all users are allowed to change (but with reg.exe not regedit.exe).注册表文件仅包含允许所有用户更改的每个用户设置(但使用 reg.exe 而不是 regedit.exe)。

reg import "%~dp0\MSScript.reg"
Pause

The alternative way is to host the interfaces yourself in a class file.另一种方法是将接口自己托管在类文件中。 You need to implement IActiveScriptSite ay a minimum.您至少需要实现 IActiveScriptSite。 See IActiveScript topic in VBS help http://download.microsoft.com/download/winscript56/Install/5.6/W982KMeXP/EN-US/scrdoc56en.exe请参阅 VBS 帮助中的 IActiveScript 主题http://download.microsoft.com/download/winscript56/Install/5.6/W982KMeXP/EN-US/scrdoc56en.exe

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Excel VBA 创建 Word 应用程序:运行时错误“429”:ActiveX 组件无法创建对象 - Creating Word Application using Excel VBA: Run-time error '429': ActiveX component can't create object 从 Excel 发送邮件 - 运行时错误“429”:ActiveX 组件无法创建对象 - Sending mails from Excel - Run-time error '429': ActiveX component can't create object 创建Outlook对象会生成-运行时错误'429':ActiveX组件无法创建对象 - Creating Outlook object generates - Run-time error '429': ActiveX component can't create object 运行时错误“ 429” activex组件无法创建对象 - run-time error '429' activex component can't create object VBA:Acrobat运行时错误429; ActiveX组件无法创建对象 - VBA: Acrobat Run time error 429; ActiveX component can't create object Excel VBA ActiveX'429'运行时错误 - Excel VBA ActiveX '429' Run-time error 使用任务计划程序在 Excel 中运行 selenium v​​ba 宏时,如何修复“运行时错误 429:ActiveX 组件无法创建对象”错误? - How to fix "Run time error 429: ActiveX Component Can't Create Object" Error when using Task Scheduler to run a selenium vba macro in Excel? ActiveX 组件无法创建 object - 429 - ActiveX component can't create object - 429 脚本在调试模式下工作,但在正常运行下不工作-错误代码:429(ActiveX组件无法创建对象) - Script working in Debug Mode but not in Normal Run - Error Code: 429(ActiveX Component Can't Create Object') 如何修复VBA中的“执行错误429:ActiveX无法创建对象”错误 - How to fix “Execution Error 429 : ActiveX can't create object” error in VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM