活动X错误与Excel 2016和延迟绑定 [英] Active X Error With Excel 2016 And Late Binding
问题描述
Microsoft Office 365 Business
,并尝试运行 Access VBA
创建一个Excel目的。这是我正在使用的Access VBA语法 Dim xl As Object,wb As Object,ws As Object,ch As Object
设置xl = CreateObject(Excel.Application)
然而,它点击 CreateObject
行,并在我的运行Office 365 Business的个人计算机上抛出下面的图片,但只能仅。如果我在运行Office 2010的计算机上运行相同的语法,它将按照它所执行的方式执行,并创建Excel对象错误。
为了能够使用 Microsoft Office 365 Business
运行此语法
编辑
这是我看到的唯一注册表项 - 它是接近的,但不完全是在评论。
一个选项是检查在尝试调用 CreateObject
之前查看CLSID是否存在。您可以使用ole32.dll函数 CLSIDFromString
来测试它(这也是VBA内部用于 CreateObject
和 GetObject
call):
'注意,这是32位通话 - 使用PtrSafe for 64bit Office。
私有声明函数CLSIDFromString Libole32.dll_
(ByVal lpsz As LongPtr,ByRef pclsid As LongPtr)As Long
您可以将它包装在一个简单的存在测试中,如下所示:
私有函数ClassIdExists(clsid As String)As Boolean
Dim ptr As LongPtr
Dim ret As Long
ret = CLSIDFromString(StrPtr(clsid),ptr)
如果ret = 0则ClassIdExists = True
结束函数
这样可以让你在你尝试创建它们(并避免使用错误处理程序来捕获不好的CLSID):
Dim xl As Object
如果ClassIdExists(Excel.Application)然后
设置xl = CreateObject(Excel.Application)
ElseIf ClassIdExists(Excel.Application.16)然后
设置xl = CreateObject(Excel.Application.16)
Else
MsgBox找不到Excel类。
结束如果
I have Microsoft Office 365 Business
installed on my PC and am attempting to run Access VBA
to create an Excel Object. This is my Access VBA syntax I am using
Dim xl As Object, wb As Object, ws As Object, ch As Object
Set xl = CreateObject("Excel.Application")
However, it hits the CreateObject
line and throws the image below, but ONLY on my PC running Office 365 Business. If I run this same syntax on a computer running Office 2010 it executes exactly as it should and creates the Excel Object error free.
What must I change in order to be able to run this syntax with Microsoft Office 365 Business
?
EDIT
This is the only Registry Key that I see - it is close, but not exactly what was stated in the comments.
One option would be to check to see if the CLSID exists before trying to call CreateObject
. You can use the ole32.dll function CLSIDFromString
to test it (this is also used by VBA internally for CreateObject
and GetObject
calls):
'Note, this is the 32bit call - use PtrSafe for 64bit Office.
Private Declare Function CLSIDFromString Lib "ole32.dll" _
(ByVal lpsz As LongPtr, ByRef pclsid As LongPtr) As Long
You can wrap it in a simple "exists" test something like this:
Private Function ClassIdExists(clsid As String) As Boolean
Dim ptr As LongPtr
Dim ret As Long
ret = CLSIDFromString(StrPtr(clsid), ptr)
If ret = 0 Then ClassIdExists = True
End Function
This lets you test for classes before you try to create them (and avoids using the error handler to catch bad CLSIDs):
Dim xl As Object
If ClassIdExists("Excel.Application") Then
Set xl = CreateObject("Excel.Application")
ElseIf ClassIdExists("Excel.Application.16") Then
Set xl = CreateObject("Excel.Application.16")
Else
MsgBox "Can't locate Excel class."
End If
这篇关于活动X错误与Excel 2016和延迟绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!