ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: netcaf

[求助] VBA中创建“MSScriptControl.ScriptControl”失败

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2019-1-13 15:14 | 显示全部楼层
yzxfelix 发表于 2018-1-30 08:12
应该不用创建,用with   CreateObject("msscriptcontrol.scriptcontrol")

                        .Lan ...

那不和Set JS = CreateObject("msscriptcontrol.scriptcontrol")一样的效果吗?一样没法用

TA的精华主题

TA的得分主题

发表于 2019-1-13 16:18 | 显示全部楼层

不想说什么,在座的各位,需要使用64位的Office吗?64位不支持ActiveX控件。

不能因为网上资源是免费的,就用高版本,如果尊重版权,我不信这么多高版本的。

TA的精华主题

TA的得分主题

发表于 2019-5-11 18:28 | 显示全部楼层
在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/72639705

补充内容 (2021-4-20 14:44):
Sub Test()
    Dim oSC As Object
    Set oSC = CreateObjectx86("MSScriptControl.ScriptControl") ' create ActiveX via x86 mshta host
    Debug.Print TypeName(oSC) ' ScriptControl
    With oSC
        '操作oSC
    End With
    CreateObjectx86 , True ' close mshta host window at the end
End Sub
Function CreateObjectx86(Optional sProgID, Optional bClose = False)
    Static oWnd As Object
    Dim bRunning As Boolean
    #If Win64 Then
        bRunning = InStr(TypeName(oWnd), "HTMLWindow") > 0
        If bClose Then
            If bRunning Then oWnd.Close
            Exit Function
        End If
        If Not bRunning Then
            Set oWnd = CreateWindow()
            oWnd.execScript "Function CreateObjectx86(sProgID): Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"
        End If
        Set CreateObjectx86 = oWnd.CreateObjectx86(sProgID)
    #Else
        Set CreateObjectx86 = CreateObject("MSScriptControl.ScriptControl")
    #End If
End Function
Function CreateWindow()
    Dim sSignature, oShellWnd, oProc
    On Error Resume Next
    sSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38)
    CreateObject("WScript.Shell").Run "%systemroot%\syswow64\mshta.exe about:""about:<head><script>moveTo(-32000,-32000);document.title='x86Host'</script><hta:application showintaskbar=no /><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""", 0, False
    Do
        For Each oShellWnd In CreateObject("Shell.Application").Windows
            Set CreateWindow = oShellWnd.GetProperty(sSignature)
            If Err.Number = 0 Then Exit Function
            Err.Clear
        Next
    Loop
End Function

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2020-2-20 10:46 | 显示全部楼层
onERR 发表于 2019-5-11 18:28
在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/726 ...

亲测成功!感谢!

TA的精华主题

TA的得分主题

发表于 2020-4-6 13:14 | 显示全部楼层
onERR 发表于 2019-5-11 18:28
在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/726 ...

学习了,谢谢

TA的精华主题

TA的得分主题

发表于 2020-4-6 15:38 | 显示全部楼层
onERR 发表于 2019-5-11 18:28
在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/726 ...

太强大了,学习了,感谢分享。

TA的精华主题

TA的得分主题

发表于 2020-5-6 15:22 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
onERR 发表于 2019-5-11 18:28
在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/726 ...

终于解决了,很强大,感谢~

TA的精华主题

TA的得分主题

发表于 2021-4-20 14:49 | 显示全部楼层

在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/72639705
  1. Sub Test()
  2.     Dim oSC As Object
  3.     Set oSC = CreateObjectx86("MSScriptControl.ScriptControl") ' create ActiveX via x86 mshta host
  4.     Debug.Print TypeName(oSC) ' ScriptControl
  5.     With oSC
  6.         '操作oSC
  7.     End With
  8.     CreateObjectx86 , True ' close mshta host window at the end
  9. End Sub
  10. Function CreateObjectx86(Optional sProgID, Optional bClose = False)
  11.     Static oWnd As Object
  12.     Dim bRunning As Boolean
  13.     #If Win64 Then
  14.         bRunning = InStr(TypeName(oWnd), "HTMLWindow") > 0
  15.         If bClose Then
  16.             If bRunning Then oWnd.Close
  17.             Exit Function
  18.         End If
  19.         If Not bRunning Then
  20.             Set oWnd = CreateWindow()
  21.             oWnd.execScript "Function CreateObjectx86(sProgID): Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"
  22.         End If
  23.         Set CreateObjectx86 = oWnd.CreateObjectx86(sProgID)
  24.     #Else
  25.         Set CreateObjectx86 = CreateObject("MSScriptControl.ScriptControl")
  26.     #End If
  27. End Function
  28. Function CreateWindow()
  29.     Dim sSignature, oShellWnd, oProc
  30.     On Error Resume Next
  31.     sSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38)
  32.     CreateObject("WScript.Shell").Run "%systemroot%\syswow64\mshta.exe about:""about:<head><script>moveTo(-32000,-32000);document.title='x86Host'</script><hta:application showintaskbar=no /><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""", 0, False
  33.     Do
  34.         For Each oShellWnd In CreateObject("Shell.Application").Windows
  35.             Set CreateWindow = oShellWnd.GetProperty(sSignature)
  36.             If Err.Number = 0 Then Exit Function
  37.             Err.Clear
  38.         Next
  39.     Loop
  40. End Function
复制代码

TA的精华主题

TA的得分主题

发表于 2021-11-18 14:23 | 显示全部楼层
onERR 发表于 2019-5-11 18:28
在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/726 ...

插个眼,日后学习一下

TA的精华主题

TA的得分主题

发表于 2022-1-11 09:58 | 显示全部楼层
onERR 发表于 2021-4-20 14:49
在x64 OFFICE中使用ScriptControl控件的方法
https://blog.csdn.net/dengnihuilaiwpl/article/details/7 ...

感谢大神分享,日后留用
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2025-3-11 12:54 , Processed in 0.025129 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表