excel - VBA cannot create new CXMLHTTPHandler
问题描述
I'm currently working on late binding due to some issues with macros not working in Excel 2013 when they worked fine in 2010. Obviously, 2010 utilizes 14.0 object library whereas 2013 uses 15.0.
Dim myHttpRequest As Object
Dim myHttpHandler as Object
Set myHttpRequest = CreateObject("MSXML2.XMLHTTP")
Set myHttpHandler = CreateObject("CXMLHTTPHandler")
This yields an ActiveX cannot create object error. I've spent over a day looking into this.
Is there some sort of resource that has to be added in order for these objects to work? Do these objects even exist in Excel's 15.0 Object Library?
I'm completely at a loss of what to do as this usually works.
解决方案
I strongly suspect, looking at this post http://dailydoseofexcel.com/archives/2006/10/09/async-xmlhttp-calls/
that you are dealing with a user defined class. If that is the case you need to copy across that class, follow the steps outlined in the link, and then simply create a new instance of that class, without need for late binding as no library is involved.
An additional step is to convert code in that class to late bound as required if other libraries are early bound referenced.
As per that link:
Dim MyXmlHttpHandler As CXMLHTTPHandler
' Create an instance of the wrapper class.
Set MyXmlHttpHandler = New CXMLHTTPHandler
The additional steps quoting from that link are:
- Export and remove the
CXMLHTTPHandler
class to a known directory - Open that file with notepad
- Find the
OnReadyStateChange
sub, and add this text after the signature:Attribute OnReadyStateChange.VB_UserMemId = 0
- Save, close and reimport the class module into the project
推荐阅读
- reporting-services - 在矩阵中重复行总计
- python - Python 正则表达式搜索不显示月份文本
- java - 我可以在一个 ejb-jar 中描述的 bean 中从队列中写入和读取消息吗?
- sql - 针对特定错误的 SQL Server 作业步骤重试尝试
- sorting - 时间调度的数据结构?
- javascript - 在官方网站上单击带有 Javascript 的按钮(chrome 扩展)
- python - Keras LSTM 自动编码器时间序列重建
- java - IntelliJ - 带有 Amazon RDS MySQL 数据库的新数据源(Spring Boot)
- android - 图像不再使用 Android 7 在 CustomRadioImageButton 上绘制
- c++ - C++ Qt:是否可以创建一种模板槽?