-2

我使用 Excel 处理 VBA,在 windows OS(32 位)和 office 2007(office 32 位)上工作正常当我开始在 Windows 8(64 位)和 office 2010(64 位)上工作时,我无法运行应用程序所以对于我添加的以下代码行,因为 excel office 2010 带有 VBA7。

#If VBA7 Then 
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 
#Else 
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 
#End If 
#If VBA7 Then 
Declare PtrSafe Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As LongPtr, ByVal dwShareMode As LongPtr, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As LongPtr, ByVal dwFlagsAndAttributes As LongPtr, ByVal hTemplateFile As LongPtr) As Long 
Declare PtrSafe Function WriteFile Lib "kernel32.dll" (ByVal hFile As LongPtr, ByRef lpBuffer As Any, ByVal nNumberOfBytesToWrite As LongPtr, ByRef lpNumberOfBytesWritten As LongPtr, ByRef lpOverlapped As LongPtr) As Long 
Declare PtrSafe Function ReadFile Lib "kernel32" (ByVal hFile As LongPtr, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As LongPtr, ByRef lpNumberOfBytesRead As LongPtr, ByRef lpOverlapped As Any) As Long 
Declare PtrSafe Function CloseHandle Lib "kernel32.dll" (ByVal hObject As LongPtr) As Long 
#Else 
Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long 
Declare Function WriteFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, ByRef lpNumberOfBytesWritten As Long, ByRef lpOverlapped As Long) As Long 
Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByRef lpOverlapped As Any) As Long 
Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long 
#End If

它工作得很好但是当我尝试访问应用程序(excel表)时,我得到了

错误“运行时错误 429 - ActiveX 组件无法创建对象”

我的问题:我只遇到 64 位 Windows 8 和 64 位 Office 2010的问题

  1. 上面声明的代码有什么错误吗?

  2. 可以强制在 64 位操作系统上运行 32 位 COM 对象吗?

在这里创建对象

Dim objScript As New ScriptControl
Dim objNavFunctions As New NavFunctions
....
....
....

objScript.Language = "vbscript" ' **// here getting error
4

1 回答 1

2

Microsoft 建议安装 32 位版本的 Office,即使您可能拥有 64 位版本的 Windows。64 位版本的功能较少,包括 ActiveX 控件和 VBA 限制等。这是 Microsoft 对此问题的引用。

“32位版本的Office中有什么,64位版本的Office不包含什么?ActiveX控件库,ComCtl这个库包含用于构建解决方案的ActiveX控件。最常用在以下微软Office 程序:Access、Excel 和 Word。SharePoint 列表控件 SharePoint Technology 中的列表视图对使用 64 位版本 Office 的人不可用。

更多关于微软文章的信息。

于 2013-04-20T16:09:35.740 回答